#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 25;
typedef long long ll;
int n; pair <ll, ll> a[MAXN];
pair <ll, ll> dp[MAXN][MAXN];
pair <ll, ll> comb (pair <ll, ll> a, pair <ll, ll> b) {
if (a.first > b.first) return a;
if (a.first < b.first) return b;
return {a.first, min(a.second, b.second)};
}
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 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) {
dp[i][j] = comb(dp[i][j], {dp[i + 1][j + 1].first + 1, dp[i + 1][j + 1].second + a[i].first});
}
}
}
cout << dp[1][0].first << " " << dp[1][0].second << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
61268 KB |
Output is correct |
2 |
Correct |
13 ms |
63836 KB |
Output is correct |
3 |
Correct |
12 ms |
58712 KB |
Output is correct |
4 |
Correct |
11 ms |
57780 KB |
Output is correct |
5 |
Correct |
13 ms |
63200 KB |
Output is correct |
6 |
Correct |
10 ms |
57692 KB |
Output is correct |
7 |
Correct |
11 ms |
63580 KB |
Output is correct |
8 |
Correct |
10 ms |
58984 KB |
Output is correct |
9 |
Correct |
10 ms |
57436 KB |
Output is correct |
10 |
Correct |
11 ms |
59632 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
61268 KB |
Output is correct |
2 |
Correct |
13 ms |
63836 KB |
Output is correct |
3 |
Correct |
12 ms |
58712 KB |
Output is correct |
4 |
Correct |
11 ms |
57780 KB |
Output is correct |
5 |
Correct |
13 ms |
63200 KB |
Output is correct |
6 |
Correct |
10 ms |
57692 KB |
Output is correct |
7 |
Correct |
11 ms |
63580 KB |
Output is correct |
8 |
Correct |
10 ms |
58984 KB |
Output is correct |
9 |
Correct |
10 ms |
57436 KB |
Output is correct |
10 |
Correct |
11 ms |
59632 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
12 ms |
61276 KB |
Output is correct |
15 |
Correct |
13 ms |
63676 KB |
Output is correct |
16 |
Correct |
11 ms |
58716 KB |
Output is correct |
17 |
Correct |
11 ms |
57948 KB |
Output is correct |
18 |
Correct |
12 ms |
63068 KB |
Output is correct |
19 |
Correct |
11 ms |
57832 KB |
Output is correct |
20 |
Correct |
11 ms |
63464 KB |
Output is correct |
21 |
Correct |
10 ms |
59004 KB |
Output is correct |
22 |
Correct |
9 ms |
57844 KB |
Output is correct |
23 |
Correct |
11 ms |
59740 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 |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
61148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
61268 KB |
Output is correct |
2 |
Correct |
13 ms |
63836 KB |
Output is correct |
3 |
Correct |
12 ms |
58712 KB |
Output is correct |
4 |
Correct |
11 ms |
57780 KB |
Output is correct |
5 |
Correct |
13 ms |
63200 KB |
Output is correct |
6 |
Correct |
10 ms |
57692 KB |
Output is correct |
7 |
Correct |
11 ms |
63580 KB |
Output is correct |
8 |
Correct |
10 ms |
58984 KB |
Output is correct |
9 |
Correct |
10 ms |
57436 KB |
Output is correct |
10 |
Correct |
11 ms |
59632 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
12 ms |
61276 KB |
Output is correct |
15 |
Correct |
13 ms |
63676 KB |
Output is correct |
16 |
Correct |
11 ms |
58716 KB |
Output is correct |
17 |
Correct |
11 ms |
57948 KB |
Output is correct |
18 |
Correct |
12 ms |
63068 KB |
Output is correct |
19 |
Correct |
11 ms |
57832 KB |
Output is correct |
20 |
Correct |
11 ms |
63464 KB |
Output is correct |
21 |
Correct |
10 ms |
59004 KB |
Output is correct |
22 |
Correct |
9 ms |
57844 KB |
Output is correct |
23 |
Correct |
11 ms |
59740 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 |
604 KB |
Output is correct |
27 |
Incorrect |
12 ms |
61148 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |