108872024-04-17 22:15:39mraronParticlescpp14Elfogadva 100/1001.866s23260 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/53ms1696 KiB
2Elfogadva5/54ms2080 KiB
3Elfogadva5/56ms2324 KiB
4Elfogadva5/516ms2684 KiB
5Elfogadva5/524ms3020 KiB
6Elfogadva5/537ms3384 KiB
7Elfogadva5/5293ms7164 KiB
8Elfogadva5/5416ms7884 KiB
9Elfogadva5/5579ms11040 KiB
10Elfogadva5/5804ms13000 KiB
11Elfogadva5/51.008s13844 KiB
12Elfogadva5/51.169s18756 KiB
13Elfogadva5/51.419s20380 KiB
14Elfogadva5/51.603s21204 KiB
15Elfogadva5/51.717s22028 KiB
16Elfogadva5/51.865s22856 KiB
17Elfogadva5/51.863s22856 KiB
18Elfogadva5/51.866s23140 KiB
19Elfogadva5/51.865s23132 KiB
20Elfogadva5/51.866s23260 KiB