#include <bits/stdc++.h>
//#include <bits/extc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
//using namespace __gnu_pbds;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned ll;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
//const int MOD = 1e9 + 7;
const int MOD = 998244353;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
/*
int add(int a, int b){ //(a + b) % 1e9 + 7
a += b;
if(a < 0){
a += MOD;
}
if(a >= MOD){
a -= MOD;
}
return a;
}
int sub(int a, int b){
a -= b;
if(a < 0) a += MOD;
return a;
}
int mult(int a, int b){
return ((ll) a * b) % MOD;
}*/
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen((s+".in").c_str(),"r",stdin);
// freopen((s+".text").c_str(),"w",stdout);
}
signed main(){
setIO();
//CHECK FOR LONG LONG!!!
//LONG LONG OVERFLOW??
int n; cin >> n;
pll art[n];
ll pref[n + 1];
fill(pref, pref + n + 1, 0);
for(int i = 0; i < n; ++i){
cin >> art[i].x >> art[i].y;
}
sort(art, art + n);
for(int i = 0; i < n; ++i){
pref[i + 1] = pref[i] + art[i].y;
}
ll ans = 0;
set<ll> poss;
for(int i = n - 1; i >= 0; --i){
poss.insert(pref[i + 1] - art[i].x);
ans = max(ans, *prev(poss.end()) - pref[i] + art[i].x);
}
cout << ans << "\n";
//CHECK FOR LONG LONG!!!
}
# |
결과 |
실행 시간 |
메모리 |
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 |
492 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
492 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 |
492 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 |
396 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
512 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 |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
492 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 |
492 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 |
396 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
512 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 |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
3 ms |
876 KB |
Output is correct |
28 |
Correct |
3 ms |
876 KB |
Output is correct |
29 |
Correct |
3 ms |
748 KB |
Output is correct |
30 |
Correct |
3 ms |
748 KB |
Output is correct |
31 |
Correct |
3 ms |
876 KB |
Output is correct |
32 |
Correct |
3 ms |
876 KB |
Output is correct |
33 |
Correct |
3 ms |
748 KB |
Output is correct |
34 |
Correct |
3 ms |
748 KB |
Output is correct |
35 |
Correct |
3 ms |
876 KB |
Output is correct |
36 |
Correct |
3 ms |
876 KB |
Output is correct |
37 |
Correct |
4 ms |
876 KB |
Output is correct |
38 |
Correct |
3 ms |
876 KB |
Output is correct |
39 |
Correct |
3 ms |
748 KB |
Output is correct |
40 |
Correct |
3 ms |
748 KB |
Output is correct |
41 |
Correct |
3 ms |
748 KB |
Output is correct |
42 |
Correct |
3 ms |
748 KB |
Output is correct |
43 |
Correct |
3 ms |
876 KB |
Output is correct |
44 |
Correct |
3 ms |
876 KB |
Output is correct |
45 |
Correct |
3 ms |
748 KB |
Output is correct |
46 |
Correct |
3 ms |
876 KB |
Output is correct |
47 |
Correct |
3 ms |
876 KB |
Output is correct |
48 |
Correct |
5 ms |
1024 KB |
Output is correct |
49 |
Correct |
4 ms |
876 KB |
Output is correct |
50 |
Correct |
3 ms |
876 KB |
Output is correct |
51 |
Correct |
3 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
492 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 |
492 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 |
396 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
512 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 |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
3 ms |
876 KB |
Output is correct |
28 |
Correct |
3 ms |
876 KB |
Output is correct |
29 |
Correct |
3 ms |
748 KB |
Output is correct |
30 |
Correct |
3 ms |
748 KB |
Output is correct |
31 |
Correct |
3 ms |
876 KB |
Output is correct |
32 |
Correct |
3 ms |
876 KB |
Output is correct |
33 |
Correct |
3 ms |
748 KB |
Output is correct |
34 |
Correct |
3 ms |
748 KB |
Output is correct |
35 |
Correct |
3 ms |
876 KB |
Output is correct |
36 |
Correct |
3 ms |
876 KB |
Output is correct |
37 |
Correct |
4 ms |
876 KB |
Output is correct |
38 |
Correct |
3 ms |
876 KB |
Output is correct |
39 |
Correct |
3 ms |
748 KB |
Output is correct |
40 |
Correct |
3 ms |
748 KB |
Output is correct |
41 |
Correct |
3 ms |
748 KB |
Output is correct |
42 |
Correct |
3 ms |
748 KB |
Output is correct |
43 |
Correct |
3 ms |
876 KB |
Output is correct |
44 |
Correct |
3 ms |
876 KB |
Output is correct |
45 |
Correct |
3 ms |
748 KB |
Output is correct |
46 |
Correct |
3 ms |
876 KB |
Output is correct |
47 |
Correct |
3 ms |
876 KB |
Output is correct |
48 |
Correct |
5 ms |
1024 KB |
Output is correct |
49 |
Correct |
4 ms |
876 KB |
Output is correct |
50 |
Correct |
3 ms |
876 KB |
Output is correct |
51 |
Correct |
3 ms |
876 KB |
Output is correct |
52 |
Correct |
290 ms |
48100 KB |
Output is correct |
53 |
Correct |
292 ms |
48356 KB |
Output is correct |
54 |
Correct |
292 ms |
48196 KB |
Output is correct |
55 |
Correct |
304 ms |
48228 KB |
Output is correct |
56 |
Correct |
354 ms |
48208 KB |
Output is correct |
57 |
Correct |
327 ms |
48224 KB |
Output is correct |
58 |
Correct |
311 ms |
48212 KB |
Output is correct |
59 |
Correct |
319 ms |
48228 KB |
Output is correct |
60 |
Correct |
299 ms |
48228 KB |
Output is correct |
61 |
Correct |
296 ms |
48224 KB |
Output is correct |
62 |
Correct |
303 ms |
48228 KB |
Output is correct |
63 |
Correct |
295 ms |
48228 KB |
Output is correct |
64 |
Correct |
291 ms |
48228 KB |
Output is correct |
65 |
Correct |
287 ms |
48228 KB |
Output is correct |
66 |
Correct |
277 ms |
48228 KB |
Output is correct |
67 |
Correct |
288 ms |
48228 KB |
Output is correct |
68 |
Correct |
310 ms |
48228 KB |
Output is correct |