#include<bits/stdc++.h>
#ifdef _DEBUG
#define ls(x) << x << ", "
#define lv(x) << #x << ": " << flush << x << ", "
#define pr(x) cout << "Line: " << __LINE__ << ", " x << endl;
#else
#define ls(x)
#define lv(x)
#define pr(x) ;
#endif
using namespace std;
typedef unsigned int uint;
typedef long long ll;
struct Art {
ll size;
ll val;
};
bool operator<(Art a, Art b) {
return a.size < b.size;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
uint n;
cin >> n;
vector<Art> a(n);
for (uint i = 0; i < n; i++) {
cin >> a[i].size >> a[i].val;
}
sort(a.begin(), a.end());
ll result = 0;
for (uint beg = 0; beg < n; beg++) {
pr(lv(beg))
ll sum = a[beg].val, max_a = a[beg].size, min_a = a[beg].size;
result = max(result, a[beg].val);
pr(lv(result))
for (uint kon = beg+1; kon < n; kon++) {
sum += a[kon].val;
max_a = max(max_a, a[kon].size);
min_a = min(min_a, a[kon].size);
pr(lv(kon) lv(a[kon].size) lv(a[kon].val))
if (sum + min_a > max_a) {
pr(lv(sum) lv(min_a) lv(max_a) lv(sum + min_a - max_a))
result = max(result, sum + min_a - max_a);
}
}
pr()
}
cout << result << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
552 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
424 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
552 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
424 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
552 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
424 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
15 ms |
592 KB |
Output is correct |
28 |
Correct |
15 ms |
592 KB |
Output is correct |
29 |
Correct |
14 ms |
336 KB |
Output is correct |
30 |
Correct |
15 ms |
336 KB |
Output is correct |
31 |
Correct |
15 ms |
592 KB |
Output is correct |
32 |
Correct |
15 ms |
848 KB |
Output is correct |
33 |
Correct |
15 ms |
336 KB |
Output is correct |
34 |
Correct |
16 ms |
668 KB |
Output is correct |
35 |
Correct |
15 ms |
336 KB |
Output is correct |
36 |
Correct |
15 ms |
336 KB |
Output is correct |
37 |
Correct |
16 ms |
592 KB |
Output is correct |
38 |
Correct |
16 ms |
592 KB |
Output is correct |
39 |
Correct |
16 ms |
592 KB |
Output is correct |
40 |
Correct |
16 ms |
592 KB |
Output is correct |
41 |
Correct |
21 ms |
336 KB |
Output is correct |
42 |
Correct |
17 ms |
336 KB |
Output is correct |
43 |
Correct |
15 ms |
592 KB |
Output is correct |
44 |
Correct |
16 ms |
336 KB |
Output is correct |
45 |
Correct |
15 ms |
592 KB |
Output is correct |
46 |
Correct |
15 ms |
760 KB |
Output is correct |
47 |
Correct |
15 ms |
592 KB |
Output is correct |
48 |
Correct |
21 ms |
592 KB |
Output is correct |
49 |
Correct |
14 ms |
592 KB |
Output is correct |
50 |
Correct |
15 ms |
336 KB |
Output is correct |
51 |
Correct |
14 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
552 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
424 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
15 ms |
592 KB |
Output is correct |
28 |
Correct |
15 ms |
592 KB |
Output is correct |
29 |
Correct |
14 ms |
336 KB |
Output is correct |
30 |
Correct |
15 ms |
336 KB |
Output is correct |
31 |
Correct |
15 ms |
592 KB |
Output is correct |
32 |
Correct |
15 ms |
848 KB |
Output is correct |
33 |
Correct |
15 ms |
336 KB |
Output is correct |
34 |
Correct |
16 ms |
668 KB |
Output is correct |
35 |
Correct |
15 ms |
336 KB |
Output is correct |
36 |
Correct |
15 ms |
336 KB |
Output is correct |
37 |
Correct |
16 ms |
592 KB |
Output is correct |
38 |
Correct |
16 ms |
592 KB |
Output is correct |
39 |
Correct |
16 ms |
592 KB |
Output is correct |
40 |
Correct |
16 ms |
592 KB |
Output is correct |
41 |
Correct |
21 ms |
336 KB |
Output is correct |
42 |
Correct |
17 ms |
336 KB |
Output is correct |
43 |
Correct |
15 ms |
592 KB |
Output is correct |
44 |
Correct |
16 ms |
336 KB |
Output is correct |
45 |
Correct |
15 ms |
592 KB |
Output is correct |
46 |
Correct |
15 ms |
760 KB |
Output is correct |
47 |
Correct |
15 ms |
592 KB |
Output is correct |
48 |
Correct |
21 ms |
592 KB |
Output is correct |
49 |
Correct |
14 ms |
592 KB |
Output is correct |
50 |
Correct |
15 ms |
336 KB |
Output is correct |
51 |
Correct |
14 ms |
336 KB |
Output is correct |
52 |
Execution timed out |
1093 ms |
13600 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |