#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 5e5+20;
const int LOG = 20;
const int MOD = 1e9+7;
const int SQRT = 520;
const int INF = 1e18;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
int n;
vector <pii> vec;
int a[MAXN], mx[MAXN];
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i=1; i<=n; i++){
int x, y; cin >> x >> y;
vec.pb({x, y});
}
vec.pb({-1, -1});
sort(vec.begin(), vec.end());
a[1] = vec[1].se;
for(int i=2; i<=n; i++){
a[i] = a[i-1];
a[i] += vec[i].se; a[i] -= vec[i].fi-vec[i-1].fi;
//cout << i << ' ' << a[i] << " te\n";
}
for(int i=n; i>=1; i--) mx[i] = max(mx[i+1], a[i]);
int ans = 0, te = 0;
for(int i=1; i<=n; i++){
ans = max(ans, mx[i]+te);
te -= vec[i].se; te += vec[i+1].fi-vec[i].fi;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |