Submission #46278

#TimeUsernameProblemLanguageResultExecution timeMemory
46278fredbrArt Exhibition (JOI18_art)C++17
50 / 100
1081 ms36272 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]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> v[i].ff >> v[i].ss; 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; 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++) { for (int j = i; j <= n; j++) { ans = max(ans, a[i]+b[j]); } } // for (int i = 1; i <= n; i++) ans = max(ans, a[i]+s[i]); cout << ans << "\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...