Submission #706720

#TimeUsernameProblemLanguageResultExecution timeMemory
706720esomerArt Exhibition (JOI18_art)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int MOD = 1e9 + 7; void solve(){ int n; cin >> n; vector<pair<ll, ll>> v(n); for(int i = 0; i < n; i++){ ll a, b; cin >> a >> b; v[i] = {a, b}; } sort(v.begin(), v.end()); ll sum = 0; ll mx = 0; ll ans = 0; for(int i = 0; i < n; i++){ if(i == 0){ mx = max(mx, v[i].first); ans = max(ans, v[i].second); sum += v[i].second; continue; } ans = max(ans, sum + v[i].second + mx - v[i].first); mx = max(mx, -sum + v[i].first); sum += v[i].second; } cout << ans << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //~ int tt; cin >> tt; int tt = 1; for(int t = 1; t <= tt; t++){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...