Submission #913865

#TimeUsernameProblemLanguageResultExecution timeMemory
913865lukameladzeArt Exhibition (JOI18_art)C++17
100 / 100
386 ms12632 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int s[500001];
int32_t main(){
	int n, ans = 0,maxx = 0; cin >> n;
	pair<int, int> p[n+1];
	s[0] = 0;
	for(int i = 1; i <= n; i++){
		cin >> p[i].first >> p[i].second;
		s[i] = 0;
	}
	sort(p+1, p+n+1);
	for (int i = 1; i <= n; i++)
        s[i] = s[i - 1] + p[i].second;
    for(int i = 1; i <= n; i++){
    	maxx = max(maxx, p[i].first - s[i - 1]);
    	ans = max(ans, s[i] + maxx - p[i].first);
	}
    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...