#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 150;
#define int long long
vector<pair<int,int>> v;
vector<vector<int>> dp;
signed main() {
fast;
int n, k;
cin >> n >> k;
v = vector<pair<int,int>>(n);
for (int i = 0; i < n; i++)
cin >> v[i].s >> v[i].f;
sort(v.begin(), v.end());
dp = vector<vector<int>>(n+1, vector<int>());
dp[0].push_back(0);
for (auto u : v) {
for (int i = n; i >= 0; i--) {
if (i+1 > u.f)
continue;
for (auto Q : dp[i])
dp[i + 1].push_back(Q + u.s);
}
}
for (int i = n; k && i >= 0; i--) {
sort(dp[i].begin(), dp[i].end(), greater<int>());
while (k && dp[i].size()) {
cout << i << " " << dp[i].back() << "\n";
k--;
dp[i].pop_back();
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
463 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
463 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
455 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5428 KB |
Output is correct |
2 |
Correct |
11 ms |
8948 KB |
Output is correct |
3 |
Correct |
3 ms |
2880 KB |
Output is correct |
4 |
Correct |
2 ms |
1620 KB |
Output is correct |
5 |
Correct |
8 ms |
8516 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
438 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
463 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |