Submission #1144744

#TimeUsernameProblemLanguageResultExecution timeMemory
1144744why1Art Exhibition (JOI18_art)C++20
50 / 100
27 ms5188 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define fi first
#define se second

const int N = 2e5;
const int mod = 1e9+7;
const ll INF = 1e18;

const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

ll a[N+1],b[N+1],ind[N+1];

bool cmp(int i,int j){
	if(a[i]==a[j])
		return b[i]<b[j];
	return a[i]<a[j];
}

void solve() {
	int n;
	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>a[i]>>b[i];
		ind[i]=i;
	}
	sort(ind+1,ind+n+1,cmp);
	ll ans=0;
	for(int i = 1; i <= n; i++){
		ll x=0;
		for(int j = i; j <= n; j++){
			x+=b[ind[j]];
			ans=max(ans,x-(a[ind[j]]-a[ind[i]]));
		}
	}
	cout<<ans<<"\n";
}

int main() {

	//freopen("cowrun.in","r",stdin);
	//freopen("cowrun.out","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

	int t=1;
	//cin>>t;
	while(t--) {
        solve();
	}

    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...