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;
const int MAXN = 2e3 + 25;
typedef long long ll;
int n; pair <ll, ll> a[MAXN];
pair <ll, ll> dp[MAXN][MAXN];
pair <ll, ll> comb (pair <ll, ll> a, pair <ll, ll> b) {
if (a.first > b.first) return a;
if (a.first < b.first) return b;
return {a.first, min(a.second, b.second)};
}
vector <pair <ll, ll>> subs;
void recurse (int pos, int sze, ll cost) {
if (pos > n) {
subs.push_back({sze, cost});
return;
}
recurse(pos + 1, sze, cost);
if (sze + 1 <= a[pos].second) recurse(pos + 1, sze + 1, cost + a[pos].first);
}
int main () {
cin >> n; int k; cin >> k;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1, [] (pair <ll, ll> &x, pair <ll, ll> &y) { return x.second < y.second; });
if (k != 1) {
recurse(1, 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';
}
return 0;
}
for (int i = n; i >= 1; i--) {
for (int j = 0; j <= n; j++) {
dp[i][j] = dp[i + 1][j];
if (j + 1 <= a[i].second) {
dp[i][j] = comb(dp[i][j], {dp[i + 1][j + 1].first + 1, dp[i + 1][j + 1].second + a[i].first});
}
}
}
cout << dp[1][0].first << " " << dp[1][0].second << '\n';
}
# | 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... |