알고리즘

C++ 알고리즘 - 백준 11047 동전 0

마루설아 2025. 1. 4. 19:39

https://www.acmicpc.net/problem/11047

 

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main(void) {
	/************** C++ Init **************/
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	/************** C++ Init **************/


	int input1, input2;
	int coin;
	int cnt = 0;
	vector<int> v;
	cin >> input1 >> input2;

	for (int i = 0; i < input1; i++) {
		cin >> coin;
		v.push_back(coin);
	}

	for (int i = v.size() - 1; i != -1; i--) {
		if (input2 / v[i] > 0) {
			cnt += input2 / v[i];
			input2 %= v[i];
		}
	}

	cout << cnt;
}