Created
April 18, 2020 13:32
-
-
Save niklasjang/d730557f55154452bba7762bc17dc871 to your computer and use it in GitHub Desktop.
[PS][그리디]/[BOJ][14247][나무자르기]
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 <iostream> | |
| #include <stack> | |
| using namespace std; | |
| stack<int> s; | |
| int n, k; | |
| int main(void) { | |
| cin >> n >> k; | |
| int coin; | |
| for (int i = 0; i < n; i++) { | |
| cin >> coin; | |
| s.push(coin); | |
| } | |
| int ans = 0; | |
| while (k) { | |
| if (k >= s.top()) { | |
| ans += k / s.top(); | |
| k %= s.top(); | |
| } | |
| s.pop(); | |
| } | |
| cout << ans << "\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment