// happy
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define int long long
//#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1e6 + 5;
const int oo = 1e16;
const int mod = 1e9 + 7;
const int base = 29; // >= so pt pb max
int n, a[N], b[N], sum, s[N], st[N << 2], ans;
pii p[N];
void update(int i,int x){
i += n - 1;
st[i] = max(st[i], x);
while(i > 1){
i /= 2;
st[i] = max(st[i], x);
}
}
int get(int l,int r){
r++;
int ret = -oo;
for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){
if(l & 1) ret = max(ret, st[l ++]);
if(r & 1) ret = max(ret, st[-- r]);
}
return ret;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i] >> b[i];
p[i] = {a[i], b[i]};
}
sort(p + 1, p + n + 1);
update(1, 0 + p[1].fi);
for(int i = 1; i <= n; i ++){
s[i] = s[i - 1] + p[i].se;
int u = get(1, i) - p[i].fi + s[i];
// cout << p[i].fi << " " << p[i].se << " h\n";
// cout << u << " " << i << " " << -s[i]+p[i + 1].fi << " " << get(1, i) << " " << s[i] << " " << " g\n";
ans = max(ans, u);
if(i + 1 <= n) update(i + 1, -s[i]+p[i + 1].fi);
}
cout << ans;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | freopen(task ".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
art.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen(task ".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4456 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4456 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4440 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4456 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4440 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
3 ms |
4700 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4700 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
2 ms |
4700 KB |
Output is correct |
35 |
Correct |
2 ms |
4700 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
2 ms |
4700 KB |
Output is correct |
38 |
Correct |
2 ms |
4700 KB |
Output is correct |
39 |
Correct |
2 ms |
4700 KB |
Output is correct |
40 |
Correct |
2 ms |
4700 KB |
Output is correct |
41 |
Correct |
2 ms |
4700 KB |
Output is correct |
42 |
Correct |
2 ms |
4700 KB |
Output is correct |
43 |
Correct |
2 ms |
4700 KB |
Output is correct |
44 |
Correct |
2 ms |
4700 KB |
Output is correct |
45 |
Correct |
2 ms |
4700 KB |
Output is correct |
46 |
Correct |
2 ms |
4700 KB |
Output is correct |
47 |
Correct |
2 ms |
4700 KB |
Output is correct |
48 |
Correct |
2 ms |
4700 KB |
Output is correct |
49 |
Correct |
2 ms |
4700 KB |
Output is correct |
50 |
Correct |
2 ms |
4700 KB |
Output is correct |
51 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4456 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4440 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
3 ms |
4700 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4700 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
2 ms |
4700 KB |
Output is correct |
35 |
Correct |
2 ms |
4700 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
2 ms |
4700 KB |
Output is correct |
38 |
Correct |
2 ms |
4700 KB |
Output is correct |
39 |
Correct |
2 ms |
4700 KB |
Output is correct |
40 |
Correct |
2 ms |
4700 KB |
Output is correct |
41 |
Correct |
2 ms |
4700 KB |
Output is correct |
42 |
Correct |
2 ms |
4700 KB |
Output is correct |
43 |
Correct |
2 ms |
4700 KB |
Output is correct |
44 |
Correct |
2 ms |
4700 KB |
Output is correct |
45 |
Correct |
2 ms |
4700 KB |
Output is correct |
46 |
Correct |
2 ms |
4700 KB |
Output is correct |
47 |
Correct |
2 ms |
4700 KB |
Output is correct |
48 |
Correct |
2 ms |
4700 KB |
Output is correct |
49 |
Correct |
2 ms |
4700 KB |
Output is correct |
50 |
Correct |
2 ms |
4700 KB |
Output is correct |
51 |
Correct |
2 ms |
4700 KB |
Output is correct |
52 |
Correct |
175 ms |
40784 KB |
Output is correct |
53 |
Correct |
186 ms |
45908 KB |
Output is correct |
54 |
Correct |
179 ms |
45984 KB |
Output is correct |
55 |
Correct |
177 ms |
45964 KB |
Output is correct |
56 |
Correct |
175 ms |
46164 KB |
Output is correct |
57 |
Correct |
185 ms |
46092 KB |
Output is correct |
58 |
Correct |
174 ms |
45956 KB |
Output is correct |
59 |
Correct |
176 ms |
45968 KB |
Output is correct |
60 |
Correct |
187 ms |
46080 KB |
Output is correct |
61 |
Correct |
185 ms |
45924 KB |
Output is correct |
62 |
Correct |
203 ms |
45976 KB |
Output is correct |
63 |
Correct |
181 ms |
45904 KB |
Output is correct |
64 |
Correct |
181 ms |
45904 KB |
Output is correct |
65 |
Correct |
194 ms |
45352 KB |
Output is correct |
66 |
Correct |
185 ms |
46024 KB |
Output is correct |
67 |
Correct |
185 ms |
46040 KB |
Output is correct |
68 |
Correct |
183 ms |
44780 KB |
Output is correct |