#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
struct P {
int sz, val;
P() {
sz = 0;
val = 0;
}
P(int _sz, int _val) {
sz = _sz;
val = _val;
}
};
const int MXN = 500005;
int n, ans = 0;
P a[MXN];
int pre[MXN];
priority_queue<pii> pq;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].sz >> a[i].val;
}
sort(a, a + n, [](P &a, P &b) {
return (a.sz == b.sz ? a.val < b.val : a.sz < b.sz);
});
for (int i = 0; i < n; i++) pre[i + 1] = pre[i] + a[i].val;
// for (int i = 0; i < n; i++) {
// for (int j = i + 1; j <= n; j++) {
// ans = max(ans, pre[j] - pre[i] - (art[j - 1].sz - art[i].sz));
// }
// }
// cout << ans << endl;
for (int j = 1; j <= n; j++) pq.push({pre[j] - a[j - 1].sz, j});
for (int i = 0; i < n; i++) {
while (pq.top().second <= i) pq.pop();
ans = max(ans, a[i].sz - pre[i] + pq.top().first);
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
4 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
4 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8148 KB |
Output is correct |
12 |
Correct |
4 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8144 KB |
Output is correct |
15 |
Correct |
4 ms |
8148 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8176 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
4 ms |
8176 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
4 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8148 KB |
Output is correct |
12 |
Correct |
4 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8144 KB |
Output is correct |
15 |
Correct |
4 ms |
8148 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8176 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
4 ms |
8176 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
5 ms |
8404 KB |
Output is correct |
28 |
Correct |
6 ms |
8296 KB |
Output is correct |
29 |
Correct |
7 ms |
8404 KB |
Output is correct |
30 |
Correct |
8 ms |
8404 KB |
Output is correct |
31 |
Correct |
6 ms |
8404 KB |
Output is correct |
32 |
Correct |
6 ms |
8404 KB |
Output is correct |
33 |
Correct |
6 ms |
8404 KB |
Output is correct |
34 |
Correct |
6 ms |
8416 KB |
Output is correct |
35 |
Correct |
6 ms |
8404 KB |
Output is correct |
36 |
Correct |
6 ms |
8404 KB |
Output is correct |
37 |
Correct |
5 ms |
8404 KB |
Output is correct |
38 |
Correct |
5 ms |
8404 KB |
Output is correct |
39 |
Correct |
6 ms |
8404 KB |
Output is correct |
40 |
Correct |
6 ms |
8404 KB |
Output is correct |
41 |
Correct |
6 ms |
8404 KB |
Output is correct |
42 |
Correct |
5 ms |
8404 KB |
Output is correct |
43 |
Correct |
6 ms |
8404 KB |
Output is correct |
44 |
Correct |
6 ms |
8404 KB |
Output is correct |
45 |
Correct |
6 ms |
8404 KB |
Output is correct |
46 |
Correct |
6 ms |
8344 KB |
Output is correct |
47 |
Correct |
7 ms |
8404 KB |
Output is correct |
48 |
Correct |
6 ms |
8404 KB |
Output is correct |
49 |
Correct |
6 ms |
8404 KB |
Output is correct |
50 |
Correct |
5 ms |
8288 KB |
Output is correct |
51 |
Correct |
6 ms |
8404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
4 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8148 KB |
Output is correct |
12 |
Correct |
4 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8144 KB |
Output is correct |
15 |
Correct |
4 ms |
8148 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8176 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
4 ms |
8176 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
5 ms |
8404 KB |
Output is correct |
28 |
Correct |
6 ms |
8296 KB |
Output is correct |
29 |
Correct |
7 ms |
8404 KB |
Output is correct |
30 |
Correct |
8 ms |
8404 KB |
Output is correct |
31 |
Correct |
6 ms |
8404 KB |
Output is correct |
32 |
Correct |
6 ms |
8404 KB |
Output is correct |
33 |
Correct |
6 ms |
8404 KB |
Output is correct |
34 |
Correct |
6 ms |
8416 KB |
Output is correct |
35 |
Correct |
6 ms |
8404 KB |
Output is correct |
36 |
Correct |
6 ms |
8404 KB |
Output is correct |
37 |
Correct |
5 ms |
8404 KB |
Output is correct |
38 |
Correct |
5 ms |
8404 KB |
Output is correct |
39 |
Correct |
6 ms |
8404 KB |
Output is correct |
40 |
Correct |
6 ms |
8404 KB |
Output is correct |
41 |
Correct |
6 ms |
8404 KB |
Output is correct |
42 |
Correct |
5 ms |
8404 KB |
Output is correct |
43 |
Correct |
6 ms |
8404 KB |
Output is correct |
44 |
Correct |
6 ms |
8404 KB |
Output is correct |
45 |
Correct |
6 ms |
8404 KB |
Output is correct |
46 |
Correct |
6 ms |
8344 KB |
Output is correct |
47 |
Correct |
7 ms |
8404 KB |
Output is correct |
48 |
Correct |
6 ms |
8404 KB |
Output is correct |
49 |
Correct |
6 ms |
8404 KB |
Output is correct |
50 |
Correct |
5 ms |
8288 KB |
Output is correct |
51 |
Correct |
6 ms |
8404 KB |
Output is correct |
52 |
Correct |
243 ms |
20288 KB |
Output is correct |
53 |
Correct |
240 ms |
33076 KB |
Output is correct |
54 |
Correct |
246 ms |
32972 KB |
Output is correct |
55 |
Correct |
251 ms |
33084 KB |
Output is correct |
56 |
Correct |
284 ms |
32960 KB |
Output is correct |
57 |
Correct |
252 ms |
33092 KB |
Output is correct |
58 |
Correct |
214 ms |
33084 KB |
Output is correct |
59 |
Correct |
196 ms |
33256 KB |
Output is correct |
60 |
Correct |
208 ms |
32972 KB |
Output is correct |
61 |
Correct |
213 ms |
32844 KB |
Output is correct |
62 |
Correct |
201 ms |
32976 KB |
Output is correct |
63 |
Correct |
196 ms |
32964 KB |
Output is correct |
64 |
Correct |
198 ms |
33076 KB |
Output is correct |
65 |
Correct |
196 ms |
33212 KB |
Output is correct |
66 |
Correct |
201 ms |
33088 KB |
Output is correct |
67 |
Correct |
206 ms |
33076 KB |
Output is correct |
68 |
Correct |
221 ms |
33080 KB |
Output is correct |