#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
int n;
long long sm[1000000], mn[1000000], mx[1000000], s[1000000], mox=-INT64_MAX;
pair<long long, int> a[500000];
void bt(int tl, int tr, int v){
if(tl==tr){
sm[v]=a[tl].s;
mx[v]=a[tl].f;
mn[v]=mx[v];
s[v]=sm[v];
}else{
int tm=(tl+tr)/2;
bt(tl, tm, v*2);
bt(tm+1, tr, v*2+1);
sm[v]=sm[v*2]+sm[v*2+1];
mx[v]=max(mx[v*2], mx[v*2+1]);
mn[v]=min(mn[v*2], mn[v*2+1]);
s[v]=sm[v]-mx[v]+mn[v];
}
mox=max(mox, s[v]);
}
pair<long long, pair<long long, long long>> get(int l, int r, int v, int tl, int tr) {
if(l<=tl&&r>=tr){
return {sm[v],{mx[v], mn[v]}};
}
if(l>tr||r<tl){
return {0,{0,INT64_MAX}};
}
int tm=(tl+tr)/2;
pair<long long, pair<long long, long long>> p1=get(l,r,v*2,tl,tm),p2=get(l,r,v*2+1,tm+1,tr);
p1.f=p1.f+p2.f;p1.s.f=max(p1.s.f, p2.s.f);p1.s.s=min(p1.s.s, p2.s.s);
mox=max(mox, p1.f-p1.s.f+p1.s.s);
long long shm=mox;
return p1;
}
int main() {
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i].f >> a[i].s;
}
sort(a, a+n);
bt(0, n-1, 1);
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
get(i, j, 1, 0, n-1);
}
}
cout << mox;
return 0;
}
Compilation message
art.cpp: In function 'std::pair<long long int, std::pair<long long int, long long int> > get(int, int, int, int, int)':
art.cpp:36:15: warning: unused variable 'shm' [-Wunused-variable]
36 | long long shm=mox;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
6 ms |
8652 KB |
Output is correct |
13 |
Correct |
5 ms |
8660 KB |
Output is correct |
14 |
Correct |
5 ms |
8540 KB |
Output is correct |
15 |
Correct |
5 ms |
8540 KB |
Output is correct |
16 |
Correct |
5 ms |
8540 KB |
Output is correct |
17 |
Correct |
5 ms |
8540 KB |
Output is correct |
18 |
Correct |
5 ms |
8540 KB |
Output is correct |
19 |
Correct |
5 ms |
8540 KB |
Output is correct |
20 |
Correct |
5 ms |
8540 KB |
Output is correct |
21 |
Correct |
5 ms |
8540 KB |
Output is correct |
22 |
Correct |
5 ms |
8652 KB |
Output is correct |
23 |
Correct |
5 ms |
8660 KB |
Output is correct |
24 |
Correct |
5 ms |
8540 KB |
Output is correct |
25 |
Correct |
5 ms |
8540 KB |
Output is correct |
26 |
Correct |
7 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
6 ms |
8652 KB |
Output is correct |
13 |
Correct |
5 ms |
8660 KB |
Output is correct |
14 |
Correct |
5 ms |
8540 KB |
Output is correct |
15 |
Correct |
5 ms |
8540 KB |
Output is correct |
16 |
Correct |
5 ms |
8540 KB |
Output is correct |
17 |
Correct |
5 ms |
8540 KB |
Output is correct |
18 |
Correct |
5 ms |
8540 KB |
Output is correct |
19 |
Correct |
5 ms |
8540 KB |
Output is correct |
20 |
Correct |
5 ms |
8540 KB |
Output is correct |
21 |
Correct |
5 ms |
8540 KB |
Output is correct |
22 |
Correct |
5 ms |
8652 KB |
Output is correct |
23 |
Correct |
5 ms |
8660 KB |
Output is correct |
24 |
Correct |
5 ms |
8540 KB |
Output is correct |
25 |
Correct |
5 ms |
8540 KB |
Output is correct |
26 |
Correct |
7 ms |
8540 KB |
Output is correct |
27 |
Execution timed out |
1045 ms |
8536 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
6 ms |
8652 KB |
Output is correct |
13 |
Correct |
5 ms |
8660 KB |
Output is correct |
14 |
Correct |
5 ms |
8540 KB |
Output is correct |
15 |
Correct |
5 ms |
8540 KB |
Output is correct |
16 |
Correct |
5 ms |
8540 KB |
Output is correct |
17 |
Correct |
5 ms |
8540 KB |
Output is correct |
18 |
Correct |
5 ms |
8540 KB |
Output is correct |
19 |
Correct |
5 ms |
8540 KB |
Output is correct |
20 |
Correct |
5 ms |
8540 KB |
Output is correct |
21 |
Correct |
5 ms |
8540 KB |
Output is correct |
22 |
Correct |
5 ms |
8652 KB |
Output is correct |
23 |
Correct |
5 ms |
8660 KB |
Output is correct |
24 |
Correct |
5 ms |
8540 KB |
Output is correct |
25 |
Correct |
5 ms |
8540 KB |
Output is correct |
26 |
Correct |
7 ms |
8540 KB |
Output is correct |
27 |
Execution timed out |
1045 ms |
8536 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |