Submission #1037370

#TimeUsernameProblemLanguageResultExecution timeMemory
1037370ivazivaArt Exhibition (JOI18_art)C++14
50 / 100
335 ms16560 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 5001 long long n; vector<pair<long long,long long>> vec; long long pref[MAXN]; map<long long,long long> poslednji; map<long long,long long> prvi; int main() { cin>>n; vec.push_back({0,0}); for (long long i=1;i<=n;i++) { long long a,b;cin>>a>>b; vec.push_back({a,b}); } sort(vec.begin(),vec.end()); pref[0]=0; for (long long i=1;i<=n;i++) pref[i]=pref[i-1]+vec[i].second; for (long long i=1;i<=n;i++) { poslednji[vec[i].first]=i; if (prvi.find(vec[i].first)==prvi.end()) prvi[vec[i].first]=i; } long long ans=pref[poslednji[vec[1].first]]; long long trenmaks=vec[1].first; for (auto&p:poslednji) { if (p.first==vec[1].first) continue; long long desno=p.second,a3=p.first; long long levo=prvi[a3]; long long s=pref[desno]-pref[levo-1]; ans=max(ans,s); long long i=levo-1; long long val=s-a3+pref[i]+trenmaks; ans=max(ans,val); trenmaks=max(trenmaks,a3-pref[i]); } 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...