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;
const ll inf = 1e18;
void solve() {
int n, k;
cin >> n >> k;
assert(k == 1);
vector<ll> dp(n + 1, inf);
dp[0] = 0;
for (int i = 0; i < n; i++) {
int w, d;
cin >> w >> d;
for (int j = d - 1; j >= 0; j--) {
dp[j + 1] = min(dp[j + 1], dp[j] + w);
}
}
for (int i = n; i > 0; i--) {
if (dp[i] != inf) {
cout << i << ' ' << dp[i];
return;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
srand(time(0));
int queries = 1;
#ifdef test_cases
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
cin >> queries;
#else
// cin >> queries;
#endif
for (int test_case = 1; test_case <= queries; test_case++) {
solve();
// cout << '\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... |