// IN THE NAME OF ALLAH
// YA IMAM REZA
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define wall cerr << "------------------------------------" << endl
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define all(x) x.begin() , x.end()
#define int ll
#define kids int tm = (tl + tr)>>1; int cl = v<<1; int cr = v<<1|1
#define test int n;cin >> n;while(n--)
#define file freopen("input.txt" , "r" , stdin); freopen("output.txt" , "w" , stdout)
#define debug while(1) cout << "TEST\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll , ll> pll;
typedef pair<pii,int> piii;
typedef pair<pll , ll> plll;
const int N = 5e5 + 10;
const int K = 400+10;
const ll mod = 1e9+7;
const ll INF = 1e18+10;
const int P = 31;
const int lg = 25;
const int delta = 30103;
int seg[N << 2];
int la[N << 2];
int n;
int a[N];
int b[N];
vector<pii> vec;
void shift(int v , int tl , int tr) {
seg[v] += la[v];
if(tl != tr) {
la[v << 1] += la[v];
la[v << 1 | 1] += la[v];
}
la[v] = 0;
}
void upd(int v , int tl , int tr , int l , int r , int x) {
shift(v , tl , tr);
if(l > r)
return;
if(tl == l && tr == r) {
la[v] += x;
shift(v , tl , tr);
return;
}
kids;
upd(cl , tl , tm , l , min(tm , r) , x);
upd(cr , tm+1 , tr , max(l , tm+1) , r , x);
seg[v] = max(seg[cl] , seg[cr]);
}
int ask(int v , int tl , int tr , int l , int r) {
shift(v , tl , tr);
if(l > r)
return -INF;
if(tl == l && tr == r)
return seg[v];
kids;
return max(ask(cl , tl , tm , l , min(tm , r)) , ask(cr , tm+1 , tr , max(l , tm+1) , r));
}
void solve() {
cin >> n;
for(int i = 1 ; i <= n ; i++)
cin >> a[i] >> b[i] , vec.pb({a[i] , b[i]});
sort(all(vec));
for(int i = 1 ; i <= n ; i++)
a[i] = vec[i-1].F , b[i] = vec[i-1].S;
int ans = -INF;
for(int i = 1 ; i <= n ; i++) {
// cout << a[i] << " " << b[i] << "\n";
upd(1 , 1 , n , 1 , i , b[i]);
upd(1 , 1 , n , 1 , i-1 , -a[i] + a[i-1]);
ans = max(ans , ask(1 , 1 , n , 1 , i));
}
cout << ans << "\n";
}
signed main()
{
fast;
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6644 KB |
Output is correct |
4 |
Correct |
1 ms |
6592 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6644 KB |
Output is correct |
4 |
Correct |
1 ms |
6592 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6596 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6604 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6644 KB |
Output is correct |
4 |
Correct |
1 ms |
6592 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6596 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6604 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6488 KB |
Output is correct |
27 |
Correct |
4 ms |
6860 KB |
Output is correct |
28 |
Correct |
4 ms |
7004 KB |
Output is correct |
29 |
Correct |
4 ms |
7000 KB |
Output is correct |
30 |
Correct |
4 ms |
7004 KB |
Output is correct |
31 |
Correct |
4 ms |
7256 KB |
Output is correct |
32 |
Correct |
4 ms |
7112 KB |
Output is correct |
33 |
Correct |
4 ms |
7004 KB |
Output is correct |
34 |
Correct |
4 ms |
7000 KB |
Output is correct |
35 |
Correct |
4 ms |
7004 KB |
Output is correct |
36 |
Correct |
4 ms |
7000 KB |
Output is correct |
37 |
Correct |
4 ms |
7000 KB |
Output is correct |
38 |
Correct |
5 ms |
7200 KB |
Output is correct |
39 |
Correct |
4 ms |
7000 KB |
Output is correct |
40 |
Correct |
4 ms |
7112 KB |
Output is correct |
41 |
Correct |
4 ms |
7000 KB |
Output is correct |
42 |
Correct |
4 ms |
7004 KB |
Output is correct |
43 |
Correct |
4 ms |
7256 KB |
Output is correct |
44 |
Correct |
4 ms |
7000 KB |
Output is correct |
45 |
Correct |
4 ms |
7004 KB |
Output is correct |
46 |
Correct |
4 ms |
7004 KB |
Output is correct |
47 |
Correct |
4 ms |
7004 KB |
Output is correct |
48 |
Correct |
4 ms |
6860 KB |
Output is correct |
49 |
Correct |
4 ms |
7000 KB |
Output is correct |
50 |
Correct |
5 ms |
7004 KB |
Output is correct |
51 |
Correct |
4 ms |
7108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6644 KB |
Output is correct |
4 |
Correct |
1 ms |
6592 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6596 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6604 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6488 KB |
Output is correct |
27 |
Correct |
4 ms |
6860 KB |
Output is correct |
28 |
Correct |
4 ms |
7004 KB |
Output is correct |
29 |
Correct |
4 ms |
7000 KB |
Output is correct |
30 |
Correct |
4 ms |
7004 KB |
Output is correct |
31 |
Correct |
4 ms |
7256 KB |
Output is correct |
32 |
Correct |
4 ms |
7112 KB |
Output is correct |
33 |
Correct |
4 ms |
7004 KB |
Output is correct |
34 |
Correct |
4 ms |
7000 KB |
Output is correct |
35 |
Correct |
4 ms |
7004 KB |
Output is correct |
36 |
Correct |
4 ms |
7000 KB |
Output is correct |
37 |
Correct |
4 ms |
7000 KB |
Output is correct |
38 |
Correct |
5 ms |
7200 KB |
Output is correct |
39 |
Correct |
4 ms |
7000 KB |
Output is correct |
40 |
Correct |
4 ms |
7112 KB |
Output is correct |
41 |
Correct |
4 ms |
7000 KB |
Output is correct |
42 |
Correct |
4 ms |
7004 KB |
Output is correct |
43 |
Correct |
4 ms |
7256 KB |
Output is correct |
44 |
Correct |
4 ms |
7000 KB |
Output is correct |
45 |
Correct |
4 ms |
7004 KB |
Output is correct |
46 |
Correct |
4 ms |
7004 KB |
Output is correct |
47 |
Correct |
4 ms |
7004 KB |
Output is correct |
48 |
Correct |
4 ms |
6860 KB |
Output is correct |
49 |
Correct |
4 ms |
7000 KB |
Output is correct |
50 |
Correct |
5 ms |
7004 KB |
Output is correct |
51 |
Correct |
4 ms |
7108 KB |
Output is correct |
52 |
Correct |
409 ms |
47620 KB |
Output is correct |
53 |
Correct |
412 ms |
47936 KB |
Output is correct |
54 |
Correct |
414 ms |
48000 KB |
Output is correct |
55 |
Correct |
407 ms |
47636 KB |
Output is correct |
56 |
Correct |
435 ms |
48016 KB |
Output is correct |
57 |
Correct |
407 ms |
47756 KB |
Output is correct |
58 |
Correct |
412 ms |
47740 KB |
Output is correct |
59 |
Correct |
408 ms |
48012 KB |
Output is correct |
60 |
Correct |
411 ms |
47860 KB |
Output is correct |
61 |
Correct |
413 ms |
48084 KB |
Output is correct |
62 |
Correct |
406 ms |
47640 KB |
Output is correct |
63 |
Correct |
408 ms |
48020 KB |
Output is correct |
64 |
Correct |
406 ms |
47884 KB |
Output is correct |
65 |
Correct |
408 ms |
48032 KB |
Output is correct |
66 |
Correct |
405 ms |
47760 KB |
Output is correct |
67 |
Correct |
409 ms |
47792 KB |
Output is correct |
68 |
Correct |
413 ms |
47992 KB |
Output is correct |