This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 2e5 + 5;
const int inf = 1e15 + 7;
int n, ans;
pii c[sz];
struct edge{
int mn, mx, sm;
} 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);
t[in].sm = t[in << 1].sm + t[in << 1 | 1].sm;
return;
}
void build(int l, int r, int in){
if(l == r){
t[in] = (edge){c[l].a, c[l].a, c[l].b};
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 get_sm(int l, int r, int in, int L, int R){
if(l > R || r < L) return 0ll;
if(l >= L && r <= R) return t[in].sm;
int mid = l + ((r - l) >> 1);
return get_sm(l, mid, in << 1, L, R) + get_sm(mid + 1, r, in << 1 | 1, L, R);
}
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;
c[i].b *= (-1);
}
sort(c+1, c+n+1);
int l{1};
for(register int i = 1; i <= n; ++i) c[i].b *= (-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), get_sm(1, n, 1, i, j));
ans = max(ans, tmp);
}
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
art.cpp: In function 'int main()':
art.cpp:69:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
69 | for(register int i = 1; i <= n; ++i){
| ^
art.cpp:75:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
75 | for(register int i = 1; i <= n; ++i) c[i].b *= (-1);
| ^
art.cpp:77:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
77 | for(register int i = 1; i < n; ++i){
| ^
art.cpp:78:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
78 | for(register int j = i; j <= n; ++j){
| ^
art.cpp:74:9: warning: unused variable 'l' [-Wunused-variable]
74 | int l{1};
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |