108882024-04-17 22:15:49mraronParticlescpp11Accepted 100/1001.792s23432 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/53ms1832 KiB
2Accepted5/54ms2168 KiB
3Accepted5/56ms2156 KiB
4Accepted5/516ms2512 KiB
5Accepted5/524ms2640 KiB
6Accepted5/537ms3012 KiB
7Accepted5/5282ms6908 KiB
8Accepted5/5400ms7612 KiB
9Accepted5/5559ms10924 KiB
10Accepted5/5773ms12528 KiB
11Accepted5/5971ms13912 KiB
12Accepted5/51.123s19008 KiB
13Accepted5/51.363s20444 KiB
14Accepted5/51.541s21252 KiB
15Accepted5/51.652s22260 KiB
16Accepted5/51.792s23196 KiB
17Accepted5/51.792s23408 KiB
18Accepted5/51.791s23432 KiB
19Accepted5/51.792s23360 KiB
20Accepted5/51.789s23360 KiB