Submission #1161324

#TimeUsernameProblemLanguageResultExecution timeMemory
1161324AzaArt Exhibition (JOI18_art)C++20
50 / 100
1097 ms8008 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);
	for(int i = 0; i < n; i++){
		cin >> p[i].F >> p[i].S;
	}
	sort(rall(p));
	int ans = 0;
	for(int i = 0; i < n; i++){
		int sm = 0;
		int mn = 1e18;
		int mx = 0;
		//cout << i << endl;
		for(int j = i; j < n; j++){
			mn = min(mn, p[j].F);
			mx = max(mx, p[j].F);
			sm += p[j].S;
			//cout << sm << " " << mn << " " << mx << " " << sm - abs(mx - mn) << endl;
			ans = max(ans, sm - abs(mx - mn));
		}
	}
	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...