# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1104111 |
2024-10-22T20:09:00 Z |
Kirill22 |
Coins (BOI06_coins) |
C++17 |
|
91 ms |
10056 KB |
#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 |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
87 ms |
9980 KB |
Output is correct |
8 |
Correct |
75 ms |
10056 KB |
Output is correct |
9 |
Correct |
91 ms |
10056 KB |
Output is correct |
10 |
Correct |
88 ms |
9808 KB |
Output is correct |