#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <pair <ll, ll>> subs;
int n; ll w[2001], dd[2001];
vector <int> cur;
void recurse (int pos, int sze, ll cost) {
if (pos == n) {
vector <int> s = cur;
sort(s.begin(), s.end(), [&] (int a, int b) {
return dd[a] < dd[b];
});
bool flag = 1;
for (int i = 0; i < sze; i++) {
flag &= i < dd[s[i]];
}
if (!flag) return;
subs.push_back({sze, cost});
return;
}
recurse(pos + 1, sze, cost);
cur.push_back(pos);
recurse(pos + 1, sze + 1, cost + w[pos]);
cur.pop_back();
}
int main () {
cin >> n; int k; cin >> k;
for (int i = 0; i < n; i++) cin >> w[i] >> dd[i];
recurse(0, 0, 0);
sort(subs.begin(), subs.end(), [] (pair <ll, ll> &a, pair <ll, ll> &b) {
return a.first == b.first ? a.second < b.second : a.first > b.first;
});
for (int i = 0; i < k; i++) {
cout << subs[i].first << " " << subs[i].second << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1830 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1830 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1781 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
8896 KB |
Output is correct |
2 |
Correct |
172 ms |
17324 KB |
Output is correct |
3 |
Correct |
44 ms |
6604 KB |
Output is correct |
4 |
Correct |
30 ms |
2508 KB |
Output is correct |
5 |
Correct |
192 ms |
18924 KB |
Output is correct |
6 |
Correct |
12 ms |
348 KB |
Output is correct |
7 |
Correct |
52 ms |
984 KB |
Output is correct |
8 |
Correct |
21 ms |
548 KB |
Output is correct |
9 |
Correct |
23 ms |
500 KB |
Output is correct |
10 |
Correct |
27 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
65 ms |
5324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1828 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1830 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |