Submission #1316997

#TimeUsernameProblemLanguageResultExecution timeMemory
1316997djsksbrbfArt Exhibition (JOI18_art)C++20
50 / 100
1097 ms20324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef pair <ll, ll> pii; #define fi first #define se second #define pb push_back signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >>n; vector <pii> v; v.pb({0, 0}); for(int i = 1 ; i <= n ; i++){ int a, b; cin >> a >> b; v.pb({a, b}); } sort(v.begin(), v.end()); ll pref[500005]; pref[0] = 0; for(int i = 1 ; i <= n ; i++)pref[i] = pref[i - 1] + v[i].se; ll prefu[500005], prefd[500005]; for(int i = 0 ; i <= n ; i++){ prefu[i] = prefd[i] = pref[i]; prefu[i] -= v[i].fi; if(i == n)continue; prefd[i] -= v[i + 1].fi; } ll ans = 0; for(int i = 0 ; i <= n ; i++){ for(int j = i + 1 ; j <= n ; j++){ ans= max(ans, prefu[j] - prefd[i]); } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...