# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
879821 |
2023-11-28T07:29:00 Z |
TAhmed33 |
Akcija (COCI21_akcija) |
C++ |
|
5000 ms |
122960 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 25;
typedef long long ll;
int n; pair <ll, ll> a[MAXN];
vector <pair <ll, ll>> dp[2][MAXN];
bool comb (pair <ll, ll> &a, pair <ll, ll> &b) {
return a.first == b.first ? a.second < b.second : a.first > b.first;
}
int main () {
cin >> n; int k; cin >> k;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1, [] (pair <ll, ll> &x, pair <ll, ll> &y) { return x.second < y.second; });
for (int j = 0; j <= n + 1; j++) dp[(n + 1) & 1][j].push_back({0, 0});
for (int i = n; i >= 1; i--) {
for (int j = 0; j <= n; j++) {
dp[i & 1][j].clear();
if (j + 1 > a[i].second) {
dp[i & 1][j] = dp[(i + 1) & 1][j];
continue;
}
int p1 = 0, p2 = 0;
vector <pair <ll, ll>> &ret = dp[i & 1][j]; vector <pair <ll, ll>> &c1 = dp[(i + 1) & 1][j];
vector <pair <ll, ll>> &c2 = dp[(i + 1) & 1][j + 1];
while ((int)ret.size() < k && p1 < (int)c1.size() && p2 < (int)c2.size()) {
pair <ll, ll> x = c1[p1], y = {c2[p2].first + 1, c2[p2].second + a[i].first};
if (comb(x, y)) {
ret.push_back(x); p1++;
} else {
ret.push_back(y); p2++;
}
}
while ((int)ret.size() < k && p1 < (int)c1.size()) ret.push_back(c1[p1++]);
while ((int)ret.size() < k && p2 < (int)c2.size()) {
ret.push_back({c2[p2].first + 1, c2[p2].second + a[i].first}); p2++;
}
}
}
for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:39:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
39 | for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
600 KB |
Output is correct |
2 |
Correct |
26 ms |
604 KB |
Output is correct |
3 |
Correct |
22 ms |
600 KB |
Output is correct |
4 |
Correct |
21 ms |
604 KB |
Output is correct |
5 |
Correct |
26 ms |
604 KB |
Output is correct |
6 |
Correct |
11 ms |
696 KB |
Output is correct |
7 |
Correct |
13 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
604 KB |
Output is correct |
9 |
Correct |
11 ms |
604 KB |
Output is correct |
10 |
Correct |
17 ms |
604 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
600 KB |
Output is correct |
2 |
Correct |
26 ms |
604 KB |
Output is correct |
3 |
Correct |
22 ms |
600 KB |
Output is correct |
4 |
Correct |
21 ms |
604 KB |
Output is correct |
5 |
Correct |
26 ms |
604 KB |
Output is correct |
6 |
Correct |
11 ms |
696 KB |
Output is correct |
7 |
Correct |
13 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
604 KB |
Output is correct |
9 |
Correct |
11 ms |
604 KB |
Output is correct |
10 |
Correct |
17 ms |
604 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 |
23 ms |
604 KB |
Output is correct |
15 |
Correct |
25 ms |
708 KB |
Output is correct |
16 |
Correct |
21 ms |
704 KB |
Output is correct |
17 |
Correct |
22 ms |
600 KB |
Output is correct |
18 |
Correct |
26 ms |
604 KB |
Output is correct |
19 |
Correct |
11 ms |
604 KB |
Output is correct |
20 |
Correct |
13 ms |
704 KB |
Output is correct |
21 |
Correct |
12 ms |
604 KB |
Output is correct |
22 |
Correct |
11 ms |
604 KB |
Output is correct |
23 |
Correct |
16 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
752 KB |
Output is correct |
2 |
Correct |
43 ms |
604 KB |
Output is correct |
3 |
Correct |
36 ms |
780 KB |
Output is correct |
4 |
Correct |
36 ms |
600 KB |
Output is correct |
5 |
Correct |
43 ms |
604 KB |
Output is correct |
6 |
Correct |
11 ms |
604 KB |
Output is correct |
7 |
Correct |
17 ms |
708 KB |
Output is correct |
8 |
Correct |
11 ms |
700 KB |
Output is correct |
9 |
Correct |
13 ms |
604 KB |
Output is correct |
10 |
Correct |
23 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1368 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1060 KB |
Output is correct |
4 |
Correct |
1 ms |
1044 KB |
Output is correct |
5 |
Correct |
3 ms |
1372 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
788 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
3 ms |
860 KB |
Output is correct |
5 |
Correct |
4 ms |
856 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
540 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
600 KB |
Output is correct |
2 |
Correct |
26 ms |
604 KB |
Output is correct |
3 |
Correct |
22 ms |
600 KB |
Output is correct |
4 |
Correct |
21 ms |
604 KB |
Output is correct |
5 |
Correct |
26 ms |
604 KB |
Output is correct |
6 |
Correct |
11 ms |
696 KB |
Output is correct |
7 |
Correct |
13 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
604 KB |
Output is correct |
9 |
Correct |
11 ms |
604 KB |
Output is correct |
10 |
Correct |
17 ms |
604 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 |
23 ms |
604 KB |
Output is correct |
15 |
Correct |
25 ms |
708 KB |
Output is correct |
16 |
Correct |
21 ms |
704 KB |
Output is correct |
17 |
Correct |
22 ms |
600 KB |
Output is correct |
18 |
Correct |
26 ms |
604 KB |
Output is correct |
19 |
Correct |
11 ms |
604 KB |
Output is correct |
20 |
Correct |
13 ms |
704 KB |
Output is correct |
21 |
Correct |
12 ms |
604 KB |
Output is correct |
22 |
Correct |
11 ms |
604 KB |
Output is correct |
23 |
Correct |
16 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
42 ms |
752 KB |
Output is correct |
28 |
Correct |
43 ms |
604 KB |
Output is correct |
29 |
Correct |
36 ms |
780 KB |
Output is correct |
30 |
Correct |
36 ms |
600 KB |
Output is correct |
31 |
Correct |
43 ms |
604 KB |
Output is correct |
32 |
Correct |
11 ms |
604 KB |
Output is correct |
33 |
Correct |
17 ms |
708 KB |
Output is correct |
34 |
Correct |
11 ms |
700 KB |
Output is correct |
35 |
Correct |
13 ms |
604 KB |
Output is correct |
36 |
Correct |
23 ms |
600 KB |
Output is correct |
37 |
Correct |
0 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
2 ms |
1368 KB |
Output is correct |
41 |
Correct |
2 ms |
1116 KB |
Output is correct |
42 |
Correct |
1 ms |
1060 KB |
Output is correct |
43 |
Correct |
1 ms |
1044 KB |
Output is correct |
44 |
Correct |
3 ms |
1372 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
788 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
1112 KB |
Output is correct |
53 |
Correct |
4 ms |
860 KB |
Output is correct |
54 |
Correct |
4 ms |
860 KB |
Output is correct |
55 |
Correct |
4 ms |
860 KB |
Output is correct |
56 |
Correct |
3 ms |
860 KB |
Output is correct |
57 |
Correct |
4 ms |
856 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
604 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
2 ms |
540 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
1 ms |
604 KB |
Output is correct |
66 |
Execution timed out |
5025 ms |
122960 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |