Submission #1214461

#TimeUsernameProblemLanguageResultExecution timeMemory
1214461santi3223Art Exhibition (JOI18_art)C++20
100 / 100
311 ms8320 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define ff(aa, bb, cc) for(ll aa = bb; aa < cc; aa++)
#define pll pair<ll, ll>
#define fi first
#define se second
#define ed "\n"
#define all(aaa) aaa.begin(), aaa.end()
#define rall(aaa) aaa.rbegin(), aaa.rend()
ll MOD = 1e9+7;

int main(){
	ll n;
	cin >> n;
	vector<pll> arr(n);
	ff(i, 0, n){
		ll a, b;
		cin >> a >> b;
		arr[i] = {a, b};
	}
	sort(all(arr));
	ll sum = 0, maxx = 0, id = 0;
	ff(i, 0, n){
		if(arr[i].se > sum+arr[i].se-(arr[i].fi-arr[id].fi)){
			id = i;
			sum = arr[i].se;
		}
		else{
			sum += arr[i].se;
		}
		maxx = max(maxx, sum-(arr[i].fi-arr[id].fi));
	}
	cout << maxx;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...