#include<bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define a first
#define b second
#define pii pair<int, int>
using namespace std;
const int sz = 5005;
const int inf = 1e15 + 7;
int n, ans;
pii c[sz];
struct edge{
int mn, mx;
} t[sz << 2];
inline void push_up(int in){
t[in].mx = max(t[in << 1].mx, t[in << 1 | 1].mx);
t[in].mn = min(t[in << 1].mn, t[in << 1 | 1].mn);
return;
}
void build(int l, int r, int in){
if(l == r){
t[in] = (edge){c[l].a, c[l].a};
return;
}
int mid = l + ((r - l) >> 1);
build(l, mid, in << 1);
build(mid + 1, r, in << 1 | 1);
push_up(in);
return;
}
int get_mn(int l, int r, int in, int L, int R){
if(l > R || r < L) return inf;
if(l >= L && r <= R) return t[in].mn;
int mid = l + ((r - l) >> 1);
return min(get_mn(l, mid, in << 1, L, R), get_mn(mid + 1, r, in << 1 | 1, L, R));
}
int get_mx(int l, int r, int in, int L, int R){
if(l > R || r < L) return -inf;
if(l >= L && r <= R) return t[in].mx;
int mid = l + ((r - l) >> 1);
return max(get_mx(l, mid, in << 1, L, R), get_mx(mid + 1, r, in << 1 | 1, L, R));
}
int pref[sz];
int comp(int mna, int mxa, int s){
return s - (mxa - mna);
}
signed main(){
SPEED;
cin >> n;
for(register int i = 1; i <= n; ++i){
cin >> c[i].a >> c[i].b;
pref[i] = pref[i - 1] + c[i].b;
c[i].b *= (-1);
}
sort(c+1, c+n+1);
build(1, n, 1);
for(register int i = 1; i < n; ++i){
for(register int j = i; j <= n; ++j){
int tmp = comp(get_mn(1, n, 1, i, j), get_mx(1, n, 1, i, j), pref[j] - pref[i-1]);
ans = max(ans, tmp);
}
}
cout << ans << '\n';
return 0;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:63:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
63 | for(register int i = 1; i <= n; ++i){
| ^
art.cpp:70:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
70 | for(register int i = 1; i < n; ++i){
| ^
art.cpp:71:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
71 | for(register int j = i; j <= n; ++j){
| ^
# |
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 |
- |