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)};
}
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; });
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... |