#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<long long,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
pair<int,int> a[n];
for (int i = 0; i < n; cin >> a[i].first >> a[i++].second);
sort(a, a + n);
long long ans = 0;
for (int l = 0; l < n; l++) {
long long mn = a[l].first, mx = a[l].first, sum = 0;
for (int r = l; r < n; r++) {
mn = min(mn, a[r].first);
mx = max(mx, a[r].first);
sum += a[r].second;
ans = max(ans, sum - (mx - mn));
}
}
cout << ans;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:17:52: warning: operation on 'i' may be undefined [-Wsequence-point]
17 | for (int i = 0; i < n; cin >> a[i].first >> a[i++].second);
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
14 ms |
608 KB |
Output is correct |
28 |
Correct |
18 ms |
604 KB |
Output is correct |
29 |
Correct |
17 ms |
604 KB |
Output is correct |
30 |
Correct |
14 ms |
604 KB |
Output is correct |
31 |
Correct |
14 ms |
604 KB |
Output is correct |
32 |
Correct |
14 ms |
604 KB |
Output is correct |
33 |
Correct |
14 ms |
604 KB |
Output is correct |
34 |
Correct |
14 ms |
660 KB |
Output is correct |
35 |
Correct |
14 ms |
604 KB |
Output is correct |
36 |
Correct |
14 ms |
604 KB |
Output is correct |
37 |
Correct |
14 ms |
660 KB |
Output is correct |
38 |
Correct |
14 ms |
656 KB |
Output is correct |
39 |
Correct |
18 ms |
604 KB |
Output is correct |
40 |
Correct |
18 ms |
604 KB |
Output is correct |
41 |
Correct |
14 ms |
604 KB |
Output is correct |
42 |
Correct |
14 ms |
656 KB |
Output is correct |
43 |
Correct |
14 ms |
656 KB |
Output is correct |
44 |
Correct |
14 ms |
604 KB |
Output is correct |
45 |
Correct |
14 ms |
656 KB |
Output is correct |
46 |
Correct |
14 ms |
604 KB |
Output is correct |
47 |
Correct |
14 ms |
472 KB |
Output is correct |
48 |
Correct |
14 ms |
604 KB |
Output is correct |
49 |
Correct |
14 ms |
604 KB |
Output is correct |
50 |
Correct |
14 ms |
604 KB |
Output is correct |
51 |
Correct |
14 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
14 ms |
608 KB |
Output is correct |
28 |
Correct |
18 ms |
604 KB |
Output is correct |
29 |
Correct |
17 ms |
604 KB |
Output is correct |
30 |
Correct |
14 ms |
604 KB |
Output is correct |
31 |
Correct |
14 ms |
604 KB |
Output is correct |
32 |
Correct |
14 ms |
604 KB |
Output is correct |
33 |
Correct |
14 ms |
604 KB |
Output is correct |
34 |
Correct |
14 ms |
660 KB |
Output is correct |
35 |
Correct |
14 ms |
604 KB |
Output is correct |
36 |
Correct |
14 ms |
604 KB |
Output is correct |
37 |
Correct |
14 ms |
660 KB |
Output is correct |
38 |
Correct |
14 ms |
656 KB |
Output is correct |
39 |
Correct |
18 ms |
604 KB |
Output is correct |
40 |
Correct |
18 ms |
604 KB |
Output is correct |
41 |
Correct |
14 ms |
604 KB |
Output is correct |
42 |
Correct |
14 ms |
656 KB |
Output is correct |
43 |
Correct |
14 ms |
656 KB |
Output is correct |
44 |
Correct |
14 ms |
604 KB |
Output is correct |
45 |
Correct |
14 ms |
656 KB |
Output is correct |
46 |
Correct |
14 ms |
604 KB |
Output is correct |
47 |
Correct |
14 ms |
472 KB |
Output is correct |
48 |
Correct |
14 ms |
604 KB |
Output is correct |
49 |
Correct |
14 ms |
604 KB |
Output is correct |
50 |
Correct |
14 ms |
604 KB |
Output is correct |
51 |
Correct |
14 ms |
656 KB |
Output is correct |
52 |
Execution timed out |
1095 ms |
20820 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |