Submission #1104111

#TimeUsernameProblemLanguageResultExecution timeMemory
1104111Kirill22Coins (BOI06_coins)C++17
100 / 100
91 ms10056 KiB
#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 timeMemoryGrader output
Fetching results...