https://www.acmicpc.net/problem/2437
#include <iostream>
#include <algorithm>
using namespace std;
int n;
const int MAX = 1000;
int weight[MAX];
// 저울
long long solution(){
sort(weight, weight+n);
if(weight[0] != 1)
return 1;
long long sum = 1;
for(int i=1;i<n;i++){
if(weight[i] > sum + 1)
break;
sum += weight[i];
}
return sum+1;
}
#include <stdio.h>
void selectionSort(int array[], int inputNum) {
for (int i = 0; i < inputNum; i++) {
for (int j = i + 1; j < inputNum; j++) {
int tmp;
if (array[i] > array[j]) {
tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
}
int main(int argc, char* argv[]) {
int inputNum;
scanf("%d", &inputNum);
int weights[1000];
for (int i = 0; i < inputNum; i++)
scanf("%d", &weights[i]);
selectionSort(weights, inputNum);
int last = 0;
for (int i = 0; i < inputNum; i++) {
if (weights[i] > last + 1) {
break;
}
last += weights[i];
}
printf("%d", last + 1);
return 0;
}