Submission #1162016

#TimeUsernameProblemLanguageResultExecution timeMemory
1162016AzaArt Exhibition (JOI18_art)C++20
100 / 100
125 ms12172 KiB
//AzaLE (Azamat Alisherov)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast,unroll-loops")
#define size(x) (int)x.size()
#define int long long
//#define endl '\n'
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F first
#define S second
template<class T> using oset = tree<T, null_type, less_equal<T>,
rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 1e9 + 7;// 119 * (1 << 23) + 1;
int binpow (int a, int n){
	int res = 1;
	while (n){
		if (n & 1){
			res = (res * a) % MOD;
		}
		a = (a * a) % MOD;
		n >>= 1;
	}
	return res % MOD;
}
void chomp(){
	int n;
	cin >> n;
	vector <pair<int, int>> p(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> p[i].F >> p[i].S;
	}
	vector <int> pref(n + 1);
	sort(all(p));
	for(int i = 1; i <= n; i++){
		pref[i] = pref[i - 1] + p[i].S;
	}
	int val = 0;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		val = max(val, p[i].F - pref[i - 1]);
		ans = max(ans, pref[i] - p[i].F + val);
		//cout << pref[i] << " " << p[i].F << " " << val << " " << ans << endl;
	}
	cout << ans;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int tasks = 1;
	//cin >> tasks;
	while(tasks--){
		chomp();
	}
}
/*

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...