# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1104111 | Kirill22 | Coins (BOI06_coins) | C++17 | 91 ms | 10056 KiB |
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;
void solve() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
vector<int> dp(50, k);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 50; j++) {
if (dp[j] >= a[i].first) {
dp[j] = k;
}
}
if (a[i].second == 1) {
//
} else {
for (int j = 49; j; j--) {
if (dp[j - 1] != k && dp[j - 1] + a[i].first < k) {
dp[j] = min(dp[j], dp[j - 1] + a[i].first);
}
}
}
}
pair<int, int> answer = {0, -1};
for (int j = 1; j < 50; j++) {
if (dp[j] != k) {
answer = max(answer, pair{j, -dp[j]});
}
}
cout << answer.first << '\n' << k + answer.second << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |