108862024-04-17 22:14:35mraronParticlescpp17Accepted 100/1001.865s22712 KiB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
struct particle {
    ll start_t, start_pos;
    ll dir;
    ll v;
    int ind;
    
    double pos_at(double T) const {
        return (double)start_pos+dir*(T-start_t)*v;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,l,k;
    cin>>n>>l>>k;
    vector<particle> x(n),y(n);
    for(int i=0;i<n;++i) {
        cin>>x[i].start_t>>x[i].v;
        x[i].dir=1;
        x[i].start_pos=0;
        x[i].ind=i;
    }
    for(int i=0;i<n;++i) {
        cin>>y[i].start_t>>y[i].v;
        y[i].dir=-1;
        y[i].start_pos=l;
        y[i].ind=i;
    }

    auto get_range=[&](double T, vector<particle>& lst) -> pair<int, int> {
        pair<int, int> res={0,0};
        for(int i=1;i<(int)lst.size();++i) {
           if(lst[res.first].pos_at(T)>lst[i].pos_at(T)) res.first=i;
           if(lst[res.second].pos_at(T)<lst[i].pos_at(T)) res.second=i;
        
        }

        return res;
    };    
    
    vector<particle> lstX, lstY;
    for(int i=0;i<n;++i) lstX.push_back(x[i]);
    for(int i=0;i<n;++i) lstY.push_back(y[i]);
        
    
    for(int i=0;i<k;++i) {
        double L=0.0, R=1e9;
        for(int j=0;j<(int)lstX.size();++j) {
            R=min(R, lstX[j].start_t+double(l)/lstX[j].v);
            R=min(R, lstY[j].start_t+double(l)/lstY[j].v);
        }
        int XX, YY;
        int its=0;
        while(its++<30) {
            double mid=(L+R)/2;
            pair<int,int> xRan=get_range(mid, lstX);
            pair<int,int> yRan=get_range(mid, lstY);
            XX=xRan.second;
            YY=yRan.first;
            if(lstX[xRan.second].pos_at(mid)<lstY[yRan.first].pos_at(mid)) L=mid;
            else R=mid;
        }
        
        cout<<lstX[XX].ind+1<<" "<<lstY[YY].ind+1<<"\n";
        swap(lstX[XX], lstX[(int)lstX.size()-1]);lstX.pop_back();
        swap(lstY[YY], lstY[(int)lstY.size()-1]);lstY.pop_back();
    }
}
SubtaskSumTestVerdictTimeMemory
subtask1100/100
1Accepted5/53ms1824 KiB
2Accepted5/54ms2208 KiB
3Accepted5/56ms2412 KiB
4Accepted5/516ms2416 KiB
5Accepted5/524ms2860 KiB
6Accepted5/537ms2988 KiB
7Accepted5/5293ms6628 KiB
8Accepted5/5416ms7708 KiB
9Accepted5/5579ms11068 KiB
10Accepted5/5804ms12852 KiB
11Accepted5/51.008s13992 KiB
12Accepted5/51.169s19008 KiB
13Accepted5/51.419s20468 KiB
14Accepted5/51.603s21124 KiB
15Accepted5/51.715s21884 KiB
16Accepted5/51.863s22712 KiB
17Accepted5/51.865s22712 KiB
18Accepted5/51.863s22704 KiB
19Accepted5/51.863s22700 KiB
20Accepted5/51.861s22708 KiB