This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |