#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 && k <= 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<>());
cout << ans[k-1].first << ' ' << ans[k-1].second << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |