#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 5e5 + 9;
const ll inf = 1e9 + 7;
ll n,st[4*N],lazy[4*N];
LL a[N];
void Pass(ll id){
ll t = lazy[id]; lazy[id] = 0;
st[id*2] += t; lazy[id*2] += t;
st[id*2 + 1] += t; lazy[id*2 + 1] += t;
}
void upd(ll id,ll l,ll r,ll u,ll v,ll val){
if (v < l||r < u) return;
if (u <= l&&r <= v){
st[id] += val; lazy[id] += val; return;
}
ll mid = (l + r)/2; Pass(id);
upd(id*2,l,mid,u,v,val); upd(id*2 + 1,mid + 1,r,u,v,val);
st[id] = max(st[id*2],st[id*2 + 1]);
}
ll Get(ll id,ll l,ll r,ll u,ll v){
if (v < l||r < u) return 0;
if (u <= l&&r <= v) return st[id];
ll mid = (l + r)/2; Pass(id);
return max(Get(id*2,l,mid,u,v),Get(id*2 + 1,mid + 1,r,u,v));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n;
for (ll i = 1;i <= n;i++) cin>>a[i].fs>>a[i].sc;
sort(a + 1,a + n + 1);
ll cur = 0,ans = 0;
for (ll i = 1;i <= n;i++){
cur += a[i].sc;
upd(1,1,n,i,i,cur - a[i].fs + a[1].fs);
}
ans = max(ans,Get(1,1,n,1,n)); //cout<<ans; return 0;
for (ll i = 2;i <= n;i++){
upd(1,1,n,i,n,a[i].fs - a[i - 1].fs - a[i - 1].sc);
ans = max(ans,Get(1,1,n,i,n)); //cout<<Get(1,1,n,i,n)<<"x\n";
}
cout<<ans;
}
Compilation message
art.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
art.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
art.cpp: In function 'int main()':
art.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
46 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
5 ms |
876 KB |
Output is correct |
28 |
Correct |
5 ms |
876 KB |
Output is correct |
29 |
Correct |
7 ms |
876 KB |
Output is correct |
30 |
Correct |
5 ms |
876 KB |
Output is correct |
31 |
Correct |
5 ms |
876 KB |
Output is correct |
32 |
Correct |
6 ms |
876 KB |
Output is correct |
33 |
Correct |
5 ms |
876 KB |
Output is correct |
34 |
Correct |
5 ms |
876 KB |
Output is correct |
35 |
Correct |
6 ms |
876 KB |
Output is correct |
36 |
Correct |
5 ms |
876 KB |
Output is correct |
37 |
Correct |
7 ms |
876 KB |
Output is correct |
38 |
Correct |
6 ms |
876 KB |
Output is correct |
39 |
Correct |
5 ms |
876 KB |
Output is correct |
40 |
Correct |
7 ms |
876 KB |
Output is correct |
41 |
Correct |
7 ms |
876 KB |
Output is correct |
42 |
Correct |
5 ms |
876 KB |
Output is correct |
43 |
Correct |
6 ms |
876 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
6 ms |
876 KB |
Output is correct |
46 |
Correct |
5 ms |
876 KB |
Output is correct |
47 |
Correct |
5 ms |
876 KB |
Output is correct |
48 |
Correct |
7 ms |
876 KB |
Output is correct |
49 |
Correct |
5 ms |
876 KB |
Output is correct |
50 |
Correct |
6 ms |
876 KB |
Output is correct |
51 |
Correct |
5 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
5 ms |
876 KB |
Output is correct |
28 |
Correct |
5 ms |
876 KB |
Output is correct |
29 |
Correct |
7 ms |
876 KB |
Output is correct |
30 |
Correct |
5 ms |
876 KB |
Output is correct |
31 |
Correct |
5 ms |
876 KB |
Output is correct |
32 |
Correct |
6 ms |
876 KB |
Output is correct |
33 |
Correct |
5 ms |
876 KB |
Output is correct |
34 |
Correct |
5 ms |
876 KB |
Output is correct |
35 |
Correct |
6 ms |
876 KB |
Output is correct |
36 |
Correct |
5 ms |
876 KB |
Output is correct |
37 |
Correct |
7 ms |
876 KB |
Output is correct |
38 |
Correct |
6 ms |
876 KB |
Output is correct |
39 |
Correct |
5 ms |
876 KB |
Output is correct |
40 |
Correct |
7 ms |
876 KB |
Output is correct |
41 |
Correct |
7 ms |
876 KB |
Output is correct |
42 |
Correct |
5 ms |
876 KB |
Output is correct |
43 |
Correct |
6 ms |
876 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
6 ms |
876 KB |
Output is correct |
46 |
Correct |
5 ms |
876 KB |
Output is correct |
47 |
Correct |
5 ms |
876 KB |
Output is correct |
48 |
Correct |
7 ms |
876 KB |
Output is correct |
49 |
Correct |
5 ms |
876 KB |
Output is correct |
50 |
Correct |
6 ms |
876 KB |
Output is correct |
51 |
Correct |
5 ms |
876 KB |
Output is correct |
52 |
Correct |
670 ms |
30296 KB |
Output is correct |
53 |
Correct |
652 ms |
31852 KB |
Output is correct |
54 |
Correct |
646 ms |
31884 KB |
Output is correct |
55 |
Correct |
677 ms |
31956 KB |
Output is correct |
56 |
Correct |
663 ms |
31980 KB |
Output is correct |
57 |
Correct |
645 ms |
31852 KB |
Output is correct |
58 |
Correct |
650 ms |
31724 KB |
Output is correct |
59 |
Correct |
670 ms |
31852 KB |
Output is correct |
60 |
Correct |
695 ms |
31852 KB |
Output is correct |
61 |
Correct |
644 ms |
31864 KB |
Output is correct |
62 |
Correct |
658 ms |
31848 KB |
Output is correct |
63 |
Correct |
643 ms |
31960 KB |
Output is correct |
64 |
Correct |
646 ms |
31724 KB |
Output is correct |
65 |
Correct |
643 ms |
32108 KB |
Output is correct |
66 |
Correct |
639 ms |
31852 KB |
Output is correct |
67 |
Correct |
643 ms |
31724 KB |
Output is correct |
68 |
Correct |
645 ms |
31852 KB |
Output is correct |