File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ ```
2+ import java.io.*;
3+ import java.util.*;
4+
5+ public class Main {
6+ private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+ private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+ private static int[] weight;
9+ private static int N, sum, answer;
10+
11+ public static void main(String[] args) throws IOException {
12+ init();
13+
14+ bw.write(answer+"\n");
15+ bw.flush();
16+ bw.close();
17+ br.close();
18+ }
19+
20+ private static void init() throws IOException {
21+ N = Integer.parseInt(br.readLine());
22+ weight = new int[N];
23+
24+ StringTokenizer st = new StringTokenizer(br.readLine());
25+ for (int i = 0; i < N; i++) {
26+ weight[i] = Integer.parseInt(st.nextToken());
27+ }
28+
29+ Arrays.sort(weight);
30+
31+ sum = 0;
32+
33+ for (int i = 0; i < N; i++) {
34+ if (weight[i] > sum+1) {
35+ break;
36+ }
37+ sum += weight[i];
38+ }
39+
40+ answer = sum+1;
41+ }
42+ }
43+ ```
You can’t perform that action at this time.
0 commit comments