File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.awt.* ;
3+ import java.io.BufferedReader ;
4+ import java.io.IOException ;
5+ import java.io.InputStreamReader ;
6+ import java.util.* ;
7+ import java.util.List ;
8+
9+
10+ public class Main {
11+
12+ static int size,ans;
13+ static int [] arr;
14+
15+
16+
17+ public static void main (String [] args ) throws IOException {
18+ init();
19+ process();
20+ print();
21+ }
22+
23+ private static void init () throws IOException {
24+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
25+ size = Integer . parseInt(br. readLine());
26+ arr = new int [size];
27+ ans = 0 ;
28+ StringTokenizer st = new StringTokenizer (br. readLine());
29+
30+ for (int i = 0 ; i < size; i++ ) {
31+ arr[i] = Integer . parseInt(st. nextToken());
32+ }
33+
34+
35+ }
36+
37+ private static void process () throws IOException {
38+ Arrays . sort(arr);
39+
40+ if ( arr[0 ] != 1 ) return ;
41+ ans = 1 ;
42+
43+ for (int i = 1 ; i < arr. length; i++ ) {
44+ if (arr[i] > ans + 1 ) {
45+ return ;
46+ }
47+ ans += arr[i];
48+
49+ }
50+
51+
52+
53+ }
54+
55+
56+ private static void print () {
57+ System . out. println(ans+ 1 );
58+ }
59+ }
60+ ```
You can’t perform that action at this time.
0 commit comments