#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<pair<int,int>> arr(n);
for (auto&[cost, d] : arr) cin >> cost >> d;
assert(n <= 20);
vector<pair<int,ll>> ans;
for (int mask = 0; mask < (1<< n); mask++) {
vector<int> d;
ll cost = 0;
for (int i = 0; i < n; i++)
if (mask&(1 << i)) {
d.push_back(arr[i].second);
cost += arr[i].first;
}
sort(d.begin(), d.end());
bool ok = true;
for (int i = 0; i < (int)d.size(); i++) {
if (d[i] <= i)ok = false;
}
if (ok) ans.emplace_back(__builtin_popcount(mask), cost);
}
sort(ans.begin(), ans.end(), greater<>());
for (int i = 0; i < k; i++)
cout << ans[i].first << ' ' << ans[i].second << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
181 ms |
8656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |