#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[MAXN][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][j].push_back({0, 0});
for (int i = n; i >= 1; i--) {
for (int j = 0; j <= n; j++) {
dp[i][j] = dp[i + 1][j];
if (j + 1 > a[i].second) continue;
if (j + 1 <= a[i].second) {
for (auto [x, y] : dp[i + 1][j + 1]) {
dp[i][j].push_back({x + 1, y + a[i].first});
}
}
sort(dp[i][j].begin(), dp[i][j].end(), comb);
while (dp[i][j].size() > k) dp[i][j].pop_back();
}
}
for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:20:27: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | for (auto [x, y] : dp[i + 1][j + 1]) {
| ^
Main.cpp:25:36: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | while (dp[i][j].size() > k) dp[i][j].pop_back();
| ~~~~~~~~~~~~~~~~^~~
Main.cpp:28:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
240980 KB |
Output is correct |
2 |
Correct |
276 ms |
252748 KB |
Output is correct |
3 |
Correct |
244 ms |
228200 KB |
Output is correct |
4 |
Correct |
234 ms |
225816 KB |
Output is correct |
5 |
Correct |
276 ms |
250696 KB |
Output is correct |
6 |
Correct |
139 ms |
199328 KB |
Output is correct |
7 |
Correct |
159 ms |
221012 KB |
Output is correct |
8 |
Correct |
141 ms |
203512 KB |
Output is correct |
9 |
Correct |
141 ms |
198992 KB |
Output is correct |
10 |
Correct |
196 ms |
220160 KB |
Output is correct |
11 |
Correct |
22 ms |
96604 KB |
Output is correct |
12 |
Correct |
22 ms |
96600 KB |
Output is correct |
13 |
Correct |
22 ms |
96856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
240980 KB |
Output is correct |
2 |
Correct |
276 ms |
252748 KB |
Output is correct |
3 |
Correct |
244 ms |
228200 KB |
Output is correct |
4 |
Correct |
234 ms |
225816 KB |
Output is correct |
5 |
Correct |
276 ms |
250696 KB |
Output is correct |
6 |
Correct |
139 ms |
199328 KB |
Output is correct |
7 |
Correct |
159 ms |
221012 KB |
Output is correct |
8 |
Correct |
141 ms |
203512 KB |
Output is correct |
9 |
Correct |
141 ms |
198992 KB |
Output is correct |
10 |
Correct |
196 ms |
220160 KB |
Output is correct |
11 |
Correct |
22 ms |
96604 KB |
Output is correct |
12 |
Correct |
22 ms |
96600 KB |
Output is correct |
13 |
Correct |
22 ms |
96856 KB |
Output is correct |
14 |
Correct |
275 ms |
240960 KB |
Output is correct |
15 |
Correct |
276 ms |
252952 KB |
Output is correct |
16 |
Correct |
236 ms |
228380 KB |
Output is correct |
17 |
Correct |
238 ms |
225856 KB |
Output is correct |
18 |
Correct |
280 ms |
250452 KB |
Output is correct |
19 |
Correct |
136 ms |
199504 KB |
Output is correct |
20 |
Correct |
167 ms |
220772 KB |
Output is correct |
21 |
Correct |
140 ms |
203508 KB |
Output is correct |
22 |
Correct |
136 ms |
198988 KB |
Output is correct |
23 |
Correct |
203 ms |
220104 KB |
Output is correct |
24 |
Correct |
21 ms |
96600 KB |
Output is correct |
25 |
Correct |
21 ms |
96604 KB |
Output is correct |
26 |
Correct |
21 ms |
96604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
327628 KB |
Output is correct |
2 |
Correct |
361 ms |
346336 KB |
Output is correct |
3 |
Correct |
311 ms |
306772 KB |
Output is correct |
4 |
Correct |
309 ms |
303696 KB |
Output is correct |
5 |
Correct |
362 ms |
342868 KB |
Output is correct |
6 |
Correct |
136 ms |
199504 KB |
Output is correct |
7 |
Correct |
161 ms |
221544 KB |
Output is correct |
8 |
Correct |
140 ms |
203588 KB |
Output is correct |
9 |
Correct |
137 ms |
200784 KB |
Output is correct |
10 |
Correct |
239 ms |
260944 KB |
Output is correct |
11 |
Correct |
21 ms |
96604 KB |
Output is correct |
12 |
Correct |
21 ms |
96600 KB |
Output is correct |
13 |
Correct |
21 ms |
96856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
101896 KB |
Output is correct |
2 |
Correct |
33 ms |
100444 KB |
Output is correct |
3 |
Correct |
30 ms |
99528 KB |
Output is correct |
4 |
Correct |
27 ms |
98964 KB |
Output is correct |
5 |
Correct |
38 ms |
102236 KB |
Output is correct |
6 |
Correct |
21 ms |
96604 KB |
Output is correct |
7 |
Correct |
27 ms |
97940 KB |
Output is correct |
8 |
Correct |
22 ms |
97112 KB |
Output is correct |
9 |
Correct |
22 ms |
97116 KB |
Output is correct |
10 |
Correct |
21 ms |
96604 KB |
Output is correct |
11 |
Correct |
21 ms |
96856 KB |
Output is correct |
12 |
Correct |
21 ms |
96600 KB |
Output is correct |
13 |
Correct |
28 ms |
99420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
115744 KB |
Output is correct |
2 |
Correct |
59 ms |
116148 KB |
Output is correct |
3 |
Correct |
50 ms |
112772 KB |
Output is correct |
4 |
Correct |
49 ms |
112292 KB |
Output is correct |
5 |
Correct |
58 ms |
116940 KB |
Output is correct |
6 |
Correct |
21 ms |
97116 KB |
Output is correct |
7 |
Correct |
24 ms |
98140 KB |
Output is correct |
8 |
Correct |
24 ms |
97888 KB |
Output is correct |
9 |
Correct |
24 ms |
98396 KB |
Output is correct |
10 |
Correct |
37 ms |
105404 KB |
Output is correct |
11 |
Correct |
21 ms |
96600 KB |
Output is correct |
12 |
Correct |
21 ms |
96988 KB |
Output is correct |
13 |
Correct |
28 ms |
100512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
240980 KB |
Output is correct |
2 |
Correct |
276 ms |
252748 KB |
Output is correct |
3 |
Correct |
244 ms |
228200 KB |
Output is correct |
4 |
Correct |
234 ms |
225816 KB |
Output is correct |
5 |
Correct |
276 ms |
250696 KB |
Output is correct |
6 |
Correct |
139 ms |
199328 KB |
Output is correct |
7 |
Correct |
159 ms |
221012 KB |
Output is correct |
8 |
Correct |
141 ms |
203512 KB |
Output is correct |
9 |
Correct |
141 ms |
198992 KB |
Output is correct |
10 |
Correct |
196 ms |
220160 KB |
Output is correct |
11 |
Correct |
22 ms |
96604 KB |
Output is correct |
12 |
Correct |
22 ms |
96600 KB |
Output is correct |
13 |
Correct |
22 ms |
96856 KB |
Output is correct |
14 |
Correct |
275 ms |
240960 KB |
Output is correct |
15 |
Correct |
276 ms |
252952 KB |
Output is correct |
16 |
Correct |
236 ms |
228380 KB |
Output is correct |
17 |
Correct |
238 ms |
225856 KB |
Output is correct |
18 |
Correct |
280 ms |
250452 KB |
Output is correct |
19 |
Correct |
136 ms |
199504 KB |
Output is correct |
20 |
Correct |
167 ms |
220772 KB |
Output is correct |
21 |
Correct |
140 ms |
203508 KB |
Output is correct |
22 |
Correct |
136 ms |
198988 KB |
Output is correct |
23 |
Correct |
203 ms |
220104 KB |
Output is correct |
24 |
Correct |
21 ms |
96600 KB |
Output is correct |
25 |
Correct |
21 ms |
96604 KB |
Output is correct |
26 |
Correct |
21 ms |
96604 KB |
Output is correct |
27 |
Correct |
337 ms |
327628 KB |
Output is correct |
28 |
Correct |
361 ms |
346336 KB |
Output is correct |
29 |
Correct |
311 ms |
306772 KB |
Output is correct |
30 |
Correct |
309 ms |
303696 KB |
Output is correct |
31 |
Correct |
362 ms |
342868 KB |
Output is correct |
32 |
Correct |
136 ms |
199504 KB |
Output is correct |
33 |
Correct |
161 ms |
221544 KB |
Output is correct |
34 |
Correct |
140 ms |
203588 KB |
Output is correct |
35 |
Correct |
137 ms |
200784 KB |
Output is correct |
36 |
Correct |
239 ms |
260944 KB |
Output is correct |
37 |
Correct |
21 ms |
96604 KB |
Output is correct |
38 |
Correct |
21 ms |
96600 KB |
Output is correct |
39 |
Correct |
21 ms |
96856 KB |
Output is correct |
40 |
Correct |
40 ms |
101896 KB |
Output is correct |
41 |
Correct |
33 ms |
100444 KB |
Output is correct |
42 |
Correct |
30 ms |
99528 KB |
Output is correct |
43 |
Correct |
27 ms |
98964 KB |
Output is correct |
44 |
Correct |
38 ms |
102236 KB |
Output is correct |
45 |
Correct |
21 ms |
96604 KB |
Output is correct |
46 |
Correct |
27 ms |
97940 KB |
Output is correct |
47 |
Correct |
22 ms |
97112 KB |
Output is correct |
48 |
Correct |
22 ms |
97116 KB |
Output is correct |
49 |
Correct |
21 ms |
96604 KB |
Output is correct |
50 |
Correct |
21 ms |
96856 KB |
Output is correct |
51 |
Correct |
21 ms |
96600 KB |
Output is correct |
52 |
Correct |
28 ms |
99420 KB |
Output is correct |
53 |
Correct |
56 ms |
115744 KB |
Output is correct |
54 |
Correct |
59 ms |
116148 KB |
Output is correct |
55 |
Correct |
50 ms |
112772 KB |
Output is correct |
56 |
Correct |
49 ms |
112292 KB |
Output is correct |
57 |
Correct |
58 ms |
116940 KB |
Output is correct |
58 |
Correct |
21 ms |
97116 KB |
Output is correct |
59 |
Correct |
24 ms |
98140 KB |
Output is correct |
60 |
Correct |
24 ms |
97888 KB |
Output is correct |
61 |
Correct |
24 ms |
98396 KB |
Output is correct |
62 |
Correct |
37 ms |
105404 KB |
Output is correct |
63 |
Correct |
21 ms |
96600 KB |
Output is correct |
64 |
Correct |
21 ms |
96988 KB |
Output is correct |
65 |
Correct |
28 ms |
100512 KB |
Output is correct |
66 |
Runtime error |
1751 ms |
524288 KB |
Execution killed with signal 9 |
67 |
Halted |
0 ms |
0 KB |
- |