Submission #1034033

#TimeUsernameProblemLanguageResultExecution timeMemory
1034033vjudge1Art Exhibition (JOI18_art)C++14
100 / 100
134 ms24844 KiB
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ii pair<int,int>
#define ill pair<ll,ll>
#define el cout<<'\n'
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
const ll mod=1e9+7;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
const int nmax=5e5;

void add ( int&a , int b ) { if ((a+=b) > mod ) a -= mod ; }
void sub ( int&a , int b ) { if ((a-=b) < 0 ) a += mod ; }

template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}

using namespace std;
ii a[nmax+5];
ll sum[nmax+5];
int val[nmax+5];
int pos[nmax+5];
int get(int x)
{
    int p=pos[x+1];
   // cout<<p<<" "<<;el;
    return (sum[p]-sum[x-1]+a[x].fi-a[p].fi);
}
signed main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   vector<pair<ll, ll>> art(n+1);
	for(int i=1; i<=n; i++){
		cin >> art[i].fi >> art[i].se;
	}
	vector<ll> pre(n+1);
	sort(art.begin()+1, art.end());
	for(int i=1; i<=n; i++){
		pre[i]=pre[i-1]+art[i].se;
	}
	ll maxi=-1e18, ans=0;
	for(int i=1; i<=n; i++){
		maxi=max(maxi, art[i].fi-pre[i-1]);
		ans=max(ans, pre[i]-art[i].fi+maxi);
	}
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...