// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 5e5+10;
const ll MOD = 1e9+7;
using namespace std;
ll mx[MAX_N*3];
ll fl[MAX_N*3];
pair<ll,ll> lr[MAX_N];
ll dp[MAX_N];
int n,y;
void shift(int k)
{
int l = k*2;
int r = k*2+1;
fl[l] += fl[k];
fl[r] += fl[k];
mx[l] += fl[k];
mx[r] += fl[k];
fl[k] = 0;
}
void update(int k)
{
mx[k] = max(mx[k*2],mx[k*2+1]);
}
void add(int l,int r,int a,int b,int k,ll x)
{
if (r<a or b<l)
return;
if (a<=l and r<=b)
{
fl[k] += x;
mx[k] += x;
return;
}
int mid = (l+r)/2;
shift(k);
add(l,mid,a,b,k*2,x);
add(mid+1,r,a,b,k*2+1,x);
update(k);
}
int main()
{
cin >> n;
y = (1<<((int)ceil(log2(n))));
ll ans = 0;
for(int i = 0;i<n;++i)
cin >> lr[i].first >> lr[i].second,ans = max(ans,lr[i].second);
sort(lr,lr+n);
add(0,y-1,0,0,1,lr[0].second);
for(int i = 1;i<n;++i)
{
add(0,y-1,0,i-1,1,-lr[i].first+lr[i-1].first+lr[i].second);
add(0,y-1,i,i,1,max(lr[i].second,mx[1]));
ans = max(ans,mx[1]);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
9 ms |
640 KB |
Output is correct |
28 |
Correct |
10 ms |
640 KB |
Output is correct |
29 |
Correct |
10 ms |
640 KB |
Output is correct |
30 |
Correct |
10 ms |
640 KB |
Output is correct |
31 |
Correct |
11 ms |
640 KB |
Output is correct |
32 |
Correct |
10 ms |
640 KB |
Output is correct |
33 |
Correct |
25 ms |
640 KB |
Output is correct |
34 |
Correct |
10 ms |
640 KB |
Output is correct |
35 |
Correct |
10 ms |
608 KB |
Output is correct |
36 |
Correct |
10 ms |
640 KB |
Output is correct |
37 |
Correct |
11 ms |
640 KB |
Output is correct |
38 |
Correct |
12 ms |
640 KB |
Output is correct |
39 |
Correct |
13 ms |
640 KB |
Output is correct |
40 |
Correct |
9 ms |
640 KB |
Output is correct |
41 |
Correct |
10 ms |
640 KB |
Output is correct |
42 |
Correct |
12 ms |
640 KB |
Output is correct |
43 |
Correct |
11 ms |
540 KB |
Output is correct |
44 |
Correct |
12 ms |
640 KB |
Output is correct |
45 |
Correct |
10 ms |
640 KB |
Output is correct |
46 |
Correct |
9 ms |
640 KB |
Output is correct |
47 |
Correct |
9 ms |
640 KB |
Output is correct |
48 |
Correct |
39 ms |
640 KB |
Output is correct |
49 |
Correct |
10 ms |
640 KB |
Output is correct |
50 |
Correct |
10 ms |
640 KB |
Output is correct |
51 |
Correct |
10 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
9 ms |
640 KB |
Output is correct |
28 |
Correct |
10 ms |
640 KB |
Output is correct |
29 |
Correct |
10 ms |
640 KB |
Output is correct |
30 |
Correct |
10 ms |
640 KB |
Output is correct |
31 |
Correct |
11 ms |
640 KB |
Output is correct |
32 |
Correct |
10 ms |
640 KB |
Output is correct |
33 |
Correct |
25 ms |
640 KB |
Output is correct |
34 |
Correct |
10 ms |
640 KB |
Output is correct |
35 |
Correct |
10 ms |
608 KB |
Output is correct |
36 |
Correct |
10 ms |
640 KB |
Output is correct |
37 |
Correct |
11 ms |
640 KB |
Output is correct |
38 |
Correct |
12 ms |
640 KB |
Output is correct |
39 |
Correct |
13 ms |
640 KB |
Output is correct |
40 |
Correct |
9 ms |
640 KB |
Output is correct |
41 |
Correct |
10 ms |
640 KB |
Output is correct |
42 |
Correct |
12 ms |
640 KB |
Output is correct |
43 |
Correct |
11 ms |
540 KB |
Output is correct |
44 |
Correct |
12 ms |
640 KB |
Output is correct |
45 |
Correct |
10 ms |
640 KB |
Output is correct |
46 |
Correct |
9 ms |
640 KB |
Output is correct |
47 |
Correct |
9 ms |
640 KB |
Output is correct |
48 |
Correct |
39 ms |
640 KB |
Output is correct |
49 |
Correct |
10 ms |
640 KB |
Output is correct |
50 |
Correct |
10 ms |
640 KB |
Output is correct |
51 |
Correct |
10 ms |
640 KB |
Output is correct |
52 |
Correct |
844 ms |
23924 KB |
Output is correct |
53 |
Correct |
909 ms |
25596 KB |
Output is correct |
54 |
Correct |
839 ms |
25720 KB |
Output is correct |
55 |
Correct |
767 ms |
25336 KB |
Output is correct |
56 |
Correct |
986 ms |
25592 KB |
Output is correct |
57 |
Correct |
872 ms |
25528 KB |
Output is correct |
58 |
Correct |
860 ms |
25572 KB |
Output is correct |
59 |
Correct |
819 ms |
25344 KB |
Output is correct |
60 |
Correct |
963 ms |
25468 KB |
Output is correct |
61 |
Execution timed out |
1070 ms |
24696 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |