Submission #46281

#TimeUsernameProblemLanguageResultExecution timeMemory
46281fredbrArt Exhibition (JOI18_art)C++17
100 / 100
128 ms24204 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef long long ll; typedef pair<ll, ll> ii; const int maxn = 500010; const ll inf = 0x3f3f3f3f3f3f3f3f; ll p[maxn]; ii v[maxn]; ll a[maxn]; ll b[maxn]; ll s[maxn]; inline ll scan () { ll result = 0; char ch; ch = getchar_unlocked(); while (true) { if (ch >= '0' && ch <= '9') break; ch = getchar_unlocked(); } result = ch-'0'; while (true) { ch = getchar_unlocked(); if (ch < '0' || ch > '9') break; result = result*10ll + (ch - '0'); } return result; } int main() { int n = scan(); for (int i = 1; i <= n; i++) v[i].ff = scan(), v[i].ss = scan(); sort(v+1, v+1+n); for (int i = 1; i <= n; i++) p[i] = p[i-1] + v[i].ss; for (int i = 1; i <= n; i++) a[i] = -p[i-1] + v[i].ff; for (int i = 1; i <= n; i++) b[i] = p[i]-v[i].ff; s[n+1] = -inf; for (int i = n; i >= 1; i--) s[i] = max(s[i+1], b[i]); ll ans = -inf; for (int i = 1; i <= n; i++) ans = max(ans, a[i]+s[i]); printf("%lld\n", ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...