Submission #418468

#TimeUsernameProblemLanguageResultExecution timeMemory
418468_Avocado_Art Exhibition (JOI18_art)C++14
100 / 100
238 ms22488 KiB
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int int64_t signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vector<pair<int, int>>v; for(int i = 0; i<n; ++i){ int a, b; cin>>a>>b; v.push_back({a, b}); } sort(v.begin(), v.end()); vector<int>prefix(n); prefix[0] = v[0].second; for(int i = 1; i<n; ++i) prefix[i] = prefix[i-1] + v[i].second; vector<int>ans(n); for(int i = 1; i<n; ++i){ int cur = prefix[i] - (v[i].first - v[0].first); ans[i] = cur; } vector<int>suffix(n); suffix[n-1] = ans[n-1]; for(int i = n-2; i>=0; --i){ suffix[i] = max(suffix[i+1], ans[i]); } /* for(auto u: suffix) cout<<u<<" "; cout<<endl; */ int out = suffix[0]; for(int i = 1; i<n-1; ++i){ int diff = (v[i].first - v[0].first) - prefix[i-1]; out = max(out, suffix[i] + diff); //if(diff > 0) ans += diff; } for(int i = 0; i<n; ++i) out = max(out, v[i].second); cout<<out; cout<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...