Submission #955960

#TimeUsernameProblemLanguageResultExecution timeMemory
955960YassirSalamaTeam Contest (JOI22_team)C++17
0 / 100
2063 ms8660 KiB
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; #define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n"; #ifdef IOI void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__); #else #define dbg(...) 1337; #endif #define endl "\n" #define pb push_back #define F first #define S second #define ll long long #define mod 1000000007 #define all(v) v.begin(),v.end() #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt") signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n; cin>>n; vector<vector<int>> v(n); for(int i=0;i<n;i++){ int a,b,c; cin>>a>>b>>c; v[i]={a,b,c}; } sort(all(v),[&](const auto p1,const auto p2){ if(p1[0]==p2[0]){ if(p1[1]==p2[1]) return p1[2]>p2[1]; else return p1[1]>p2[1]; } return p1[0]>p2[0]; }); int ans=0; // for(auto x:v){ // dbg(x[0],x[1],x[2]) // } vector<pair<int,int>> a; for(int i=0;i<n;i++){ a.emplace_back(v[i][1],v[i][2]); } sort(all(a),greater<pair<int,int>>()); for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ if(v[j][0]!=v[i][0]) break; if(find(all(a),make_pair(v[j][1],v[j][2]))!=a.end()) a.erase(find(all(a),make_pair(v[j][1],v[j][2]))); } if(a.empty()) break; int x=a.size(); int suff[x]; for(int i=x-1;i>=0;i--){ suff[i]=a[i].S; if(i!=x-1) suff[i]=max(suff[i],suff[i+1]); } for(int j=0;j<x;j++){ int mn=a[j].S; if(j+1>=x) continue; int f=suff[j+1]; if(f>mn) ans=max(ans,f+a[j].F+v[i][0]); } } if(ans==0){ cout<<-1<<endl; return 0; } cout<<ans<<endl; }
#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...