Submission #955311

#TimeUsernameProblemLanguageResultExecution timeMemory
955311LCJLYTeam Contest (JOI22_team)C++14
100 / 100
110 ms17076 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl; typedef pair<int,int>pii; typedef pair<pii,pii>pi2; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); void solve(){ int n; cin >> n; array<int,3> arr[n]; for(int x=0;x<n;x++){ cin >> arr[x][0] >> arr[x][1] >> arr[x][2]; } sort(arr,arr+n); reverse(arr,arr+n); int best=-1; priority_queue<pii>pq,pq2; bool done[n+5]; memset(done,0,sizeof(done)); for(int x=0;x<n;x++){ pq.push({arr[x][1],x}); pq2.push({arr[x][2],x}); } //for(int x=0;x<n;x++){ //cout << arr[x][0] << " " << arr[x][1] << " " << arr[x][2] << endl; //} int ptr=0; for(int x=0;x<n;x++){ while(ptr<n&&arr[ptr][0]>=arr[x][0]){ done[ptr]=true; ptr++; } pii cur={-1,-1}; pii cur2={-1,-1}; while(!pq.empty()&&!pq2.empty()){ pii hold=pq.top(); pii hold2=pq2.top(); bool nxt=false; if(done[hold.second]){ pq.pop(); nxt=true; } if(done[hold2.second]){ pq2.pop(); nxt=true; } if(nxt) continue; if(arr[hold.second][2]>=hold2.first){ pq.pop(); done[hold.second]=true; } else if(arr[hold2.second][1]>=hold.first){ pq2.pop(); done[hold2.second]=true; } else break; } cur={-1,-1}; cur2={-1,-1}; if(!pq.empty()) cur=pq.top(); if(!pq2.empty()) cur2=pq2.top(); //show2(cur.first,cur.first,cur2.first,cur2.first); //show2(cur.second,cur.second,cur2.second,cur2.second); if(cur.first>arr[x][1]&&cur2.first>arr[x][2]){ best=max(best,arr[x][0]+cur.first+cur2.first); } //show4(done,done); } cout << best; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...