Submission #914815

#TimeUsernameProblemLanguageResultExecution timeMemory
914815NurislamArt Exhibition (JOI18_art)C++14
100 / 100
177 ms24912 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long 
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vi> vv;
const int N = 2e6+4, inf = 1e8;

void solve(){
	int n;
	cin >> n;
	vii v(n);
	for(int i = 0; i < n; i++)cin >> v[i].ff >> v[i].ss;
	sort(all(v));
	int ans = -1e18;
	int pr[n]{};
	for(int i = 0; i < n; i++)pr[i+1] = pr[i] + v[i].ss;
	int mn = -v[0].ff;
	for(int r = 0; r < n; r++){
		ans = max(ans, pr[r+1] - v[r].ff - mn);
        mn = min(mn, pr[r+1] - v[r+1].ff);
	}
	cout << ans << '\n';
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int test = 1;
	//~ cin >> test;
	while(test--){
		solve();
	}
}










Compilation message (stderr)

art.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...