Skip to content

Instantly share code, notes, and snippets.

@niklasjang
Created April 18, 2020 13:32
Show Gist options
  • Select an option

  • Save niklasjang/d730557f55154452bba7762bc17dc871 to your computer and use it in GitHub Desktop.

Select an option

Save niklasjang/d730557f55154452bba7762bc17dc871 to your computer and use it in GitHub Desktop.
[PS][그리디]/[BOJ][14247][나무자르기]
#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