174352025-07-16 11:58:34peti1234Particlescpp17Wrong answer 40/1002.081s8756 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> sorx, sory;
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    long double l;
    int n,k; cin >> n >> l >> k;

    vector<pair<long double,long double>> x(n),y(n);
    for (int i = 0; i < n; i++) {
        long double a, b;
        cin >> a >> b;
        x[i]={a, b};
    }
    for (int i = 0; i < n; i++) {
        long double a, b;
        cin >> a >> b;
        y[i]={a, b};
    }

    // sorx, sory-ba a k  leggyorsabb

    long double lo = -1, h = 3e9;
    for (int it=0; it<100; it++) {
        long double m = (lo+h)/2;
        vector<pair<long double, int> > x1, y1;
        for (int i = 0; i < n; i++) {
            x1.push_back({(m-x[i].first)*x[i].second,i});
        }
        for (int i = 0; i < n; i++) {
            y1.push_back({(m-y[i].first)*y[i].second,i});
        }
        sort(x1.begin(), x1.end());
        sort(y1.begin(), y1.end());
        if (x1[n-k].first+y1[n-k].first > l) h = m;
        else lo = m;
        if(it+1 == 100) {
            //cout << "vege " << lo << "\n";
            for (int i = n-1; i >= n-k; i--) sorx.push_back(x1[i].second), sory.push_back(y1[i].second);
            long double sum=x1[n-k].first+y1[n-k].first, eps=1e-5;
            assert(l-eps<sum && sum<l+eps);
        }
    }

    assert(0<lo && h<2e9);
    assert(sorx.size()==k && sory.size()==k);

    vector<pair<long double, pair<int, int> > > a;
    for (int i:sorx) {
        for (int j:sory) {
            if (x[i].first < y[j].first) a.push_back({(l-(y[j].first-x[i].first)*x[i].second)/(x[i].second+y[j].second)+((y[j].first)),{i,j}});
            else a.push_back({(l-(x[i].first-y[j].first)*y[j].second)/(x[i].second+y[j].second)+((x[i].first)),{i,j}});
        }
    }
    sort(a.begin(), a.end());
    vector<bool> w1(n, 0),w2(n, 0);
    for (int i = 0; i < a.size(); i++) {
        int x=a[i].second.first, y=a[i].second.second;
        if (!w1[x] && !w2[y]) {
            w1[x] = true;
            w2[y] = true;
            cout << x+1 << ' ' << y+1 << '\n';
            k--;
            if (k == 0) break;
        }
    }
}
/*
1 1 1
0 1000000000
0 1000000000
*/
SubtaskSumTestVerdictTimeMemory
subtask140/100
1Accepted5/51ms512 KiB
2Wrong answer0/53ms820 KiB
3Wrong answer0/54ms564 KiB
4Wrong answer0/59ms820 KiB
5Wrong answer0/516ms804 KiB
6Wrong answer0/525ms968 KiB
7Accepted5/5349ms2268 KiB
8Accepted5/5483ms2612 KiB
9Accepted5/5688ms3724 KiB
10Accepted5/5976ms4600 KiB
11Accepted5/51.157s5224 KiB
12Wrong answer0/51.412s6752 KiB
13Accepted5/51.664s7500 KiB
14Accepted5/51.766s7884 KiB
15Wrong answer0/51.906s8260 KiB
16Time limit exceeded0/52.078s8748 KiB
17Time limit exceeded0/52.081s8748 KiB
18Time limit exceeded0/52.078s8756 KiB
19Time limit exceeded0/52.062s8752 KiB
20Time limit exceeded0/52.049s8748 KiB