#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 a(n);
for(int i = 0; i < n; i++){
cin >> a[i].ff >> a[i].ss;
}sort(all(a));
int pr[n+1]{};
for(int i = 0; i < n; i++)pr[i+1] = pr[i]+a[i].ss;
int ans = a[0].ff-a[0].ss, l = 0, r = 0;
while(r < n){
if(r == l && r == n-1)r++;
else if(pr[r+2] - pr[l] - (a[r+1].ff-a[l].ff) > a[r+1].ss-a[r+1].ff)r++;
else l = r;
ans = max(ans, pr[r+1] - pr[l] - (a[r].ff - a[l].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
art.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |