Recent Posts
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Today
Total
관리 메뉴

Try

[Programmers/C++] 저울 본문

Algorithm/Programmers

[Programmers/C++] 저울

HAS3ONG 2019. 3. 24. 23:12

출처

https://programmers.co.kr/learn/courses/30/lessons/42886?language=cpp


소스


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <vector>
#include <algorithm>
 
using namespace std;
 
int solution(vector<int> w){
    int answer, sum = 0;
    
    sort(w.begin(), w.end());
    
    for(int i = 0; i < w.size(); i++){
        if (sum + 1 >= w[i]){
            sum = sum + w[i];
        }
        else{
            break;
        }
    }
    
    return answer = sum + 1;
}
cs


Comments