Submission #913861

#TimeUsernameProblemLanguageResultExecution timeMemory
913861cotArt Exhibition (JOI18_art)C++14
100 / 100
167 ms16008 KiB
#include <iostream> #include <array> #include <algorithm> #include <map> #include <climits> #define int long long #define ff first #define ss second #define pb push_back #define pp pop_back #define all(x) x.begin(),x.end() #define pii pair <int,int> #define r0 return 0 using namespace std; const int N = 5 * 1e5 + 5; int x,m,k,n,l,r,ans,cheese; int pref[N],p[N],mn; pii a[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].ff >> a[i].ss; } sort(a + 1,a + 1 + n); p[0] = -a[1].ff; pref[0] = 0; for (int i = 1; i <= n; i++){ pref[i] = pref[i - 1] + a[i].ss; p[i] = min(p[i - 1],pref[i] - a[i + 1].ff); } k = -LLONG_MAX; for (int i = 1; i <= n; i++) { k = max(k,pref[i] - a[i].ff - p[i - 1]); } cout << k << endl; r0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...