백준 2437 저울

2437 저울

초등부 문제 나는 어떡하지

풀이

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin>>N;
    vector<int> weights(N);
    for(auto &weight:weights) {
        cin>>weight;
    }
    sort(weights.begin(), weights.end());

    int ret=0;
    for(auto &weight:weights) {
        if(weight>ret+1)
            break;
        ret+=weight;
    }
    cout<<ret+1;
    //std::cout << "Hello, World!" << std::endl;
    return 0;
}

[jungin]
Written by@[jungin]
안녕하세요

GitHub