Created
July 13, 2026 06:41
-
-
Save raiyansarker/51ba7286e7d3d1ed327408d0789d9696 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| using ll = long long; | |
| ll change(int t, vector<int> &v, vector<int> &dp) { | |
| if (t == 0) return 0; | |
| ll m = INT_MAX; | |
| if (dp[t] != -1) return dp[t]; | |
| for (auto coin : v) { | |
| if (t - coin >= 0) m = min(m, change(t - coin, v, dp) + 1); | |
| } | |
| return dp[t] = m; | |
| } | |
| int main() { | |
| int n, t; cin >> n >> t; | |
| vector<int> v(n); | |
| vector<int> dp(t + 1, -1); | |
| for (auto &d : v) cin >> d; | |
| cout << change(t, v, dp) << endl; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int main() { | |
| int n, t; cin >> n >> t; | |
| vector<int> v; | |
| while (n--) { | |
| int x; cin >> x; | |
| v.push_back(x); | |
| } | |
| int c = 0; | |
| sort(v.begin(), v.end(), greater<int>()); | |
| for (auto d : v) { | |
| int coins = (t / d); | |
| c += coins; | |
| t %= d; | |
| } | |
| cout << c << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment