Submission #115967

#TimeUsernameProblemLanguageResultExecution timeMemory
115967oolimryArt Exhibition (JOI18_art)C++14
100 / 100
360 ms24828 KiB
#include <bits/stdc++.h> using namespace std; int main() { //freopen("i.txt","r",stdin); ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; typedef pair<long long, long long> ii; ii arr[n]; for(int i = 0;i < n;i++){ cin >> arr[i].first >> arr[i].second; } sort(arr,arr+n); long long pre[n]; pre[0] = arr[0].second; for(int i = 1;i < n;i++){ pre[i] = pre[i-1] + arr[i].second; } long long maxv = 0ll; long long ans = 0ll; for(int i = 0;i < n;i++){ ans = max(ans, arr[i].second); ans = max(pre[i] - arr[i].first + maxv, ans); long long v = arr[i].first; if(i != 0) v -= pre[i-1]; maxv = max(maxv, v); } cout << ans; 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...