Submission #418392

#TimeUsernameProblemLanguageResultExecution timeMemory
418392_Avocado_Art Exhibition (JOI18_art)C++14
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int int64_t signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vector<pair<int, int>>v; for(int i = 0; i<n; ++i){ int a, b; cin>>a>>b; v.push_back({a, b}); } sort(v.begin(), v.end()); vector<int>prefix(n); prefix[0] = v[0].second; for(int i = 1; i<n; ++i) prefix[i] = prefix[i-1] + v[i].second; int ans = -1e18; for(int i = 1; i<n; ++i){ int cur = prefix[i] - (v[i].first - v[0].first); ans = max(ans, cur); } for(int i = 1; i<n-1; ++i){ int diff = (v[i].first - v[0].first) - prefix[i-1]; if(diff > 0) ans += diff; } cout<<ans; cout<<'\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...