108852024-04-17 21:33:17mraronParticlescpp17Time limit exceeded 65/1002.075s21388 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++<40) {
            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
subtask165/100
1Accepted5/53ms1828 KiB
2Accepted5/54ms2168 KiB
3Accepted5/57ms2532 KiB
4Accepted5/519ms2796 KiB
5Accepted5/529ms3112 KiB
6Accepted5/548ms3216 KiB
7Accepted5/5370ms7156 KiB
8Accepted5/5528ms8048 KiB
9Accepted5/5737ms11352 KiB
10Accepted5/51.023s12996 KiB
11Accepted5/51.282s14184 KiB
12Accepted5/51.486s19288 KiB
13Accepted5/51.804s20740 KiB
14Time limit exceeded0/52.046s21388 KiB
15Time limit exceeded0/52.075s12240 KiB
16Time limit exceeded0/52.066s12984 KiB
17Time limit exceeded0/52.046s13000 KiB
18Time limit exceeded0/52.065s13256 KiB
19Time limit exceeded0/52.065s13536 KiB
20Time limit exceeded0/52.069s13380 KiB