108862024-04-17 22:14:35mraronParticlescpp17Elfogadva 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();
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask1100/100
1Elfogadva5/53ms1824 KiB
2Elfogadva5/54ms2208 KiB
3Elfogadva5/56ms2412 KiB
4Elfogadva5/516ms2416 KiB
5Elfogadva5/524ms2860 KiB
6Elfogadva5/537ms2988 KiB
7Elfogadva5/5293ms6628 KiB
8Elfogadva5/5416ms7708 KiB
9Elfogadva5/5579ms11068 KiB
10Elfogadva5/5804ms12852 KiB
11Elfogadva5/51.008s13992 KiB
12Elfogadva5/51.169s19008 KiB
13Elfogadva5/51.419s20468 KiB
14Elfogadva5/51.603s21124 KiB
15Elfogadva5/51.715s21884 KiB
16Elfogadva5/51.863s22712 KiB
17Elfogadva5/51.865s22712 KiB
18Elfogadva5/51.863s22704 KiB
19Elfogadva5/51.863s22700 KiB
20Elfogadva5/51.861s22708 KiB