๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 11047๋ฒˆ - ๋™์ „ 0

by dkswnkk 2021. 10. 26.
 

11047๋ฒˆ: ๋™์ „ 0

์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๋™์ „์˜ ๊ฐ€์น˜ Ai๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2์ธ ๊ฒฝ์šฐ์— Ai๋Š” Ai-1์˜ ๋ฐฐ์ˆ˜)

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    int T, K; //T=ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค K=๊ฐ€๊ฒฉ 
    int cnt = 0; //cnt=๋™์ „ ๊ฐฏ์ˆ˜ ์ตœ์†Œ๊ฐ’
    vector<int> v;
    cin >> T >> K;

    while (T--) {
        int N; // ๋™์ „ ์ข…๋ฅ˜
        cin >> N;
        v.push_back(N);
    }
    sort(v.begin(), v.end(),greater<int>());

    for (int i = 0; i < v.size(); i++) {
         if (K == 0) break;
        else if (K >= v[i]) {
            cnt += K / v[i];
            K %= v[i];
        }
    }
    cout << cnt;

}

๋Œ“๊ธ€