-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplantingtrees.java
56 lines (36 loc) · 934 Bytes
/
plantingtrees.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class plantingtrees {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int trees = scan.nextInt();
int[] field = new int[trees];
for(int i=0; i < trees; i++)
{
field[i]=scan.nextInt();
}
ArrayList<Integer> newfield = new ArrayList<Integer>();
for(int i=0; i < trees; i++)
{
newfield.add(field[i]);
}
Collections.sort(newfield);
Collections.reverse(newfield);
for(int i=0; i < trees; i++)
{
newfield.set(i, newfield.get(i) + 1);
}
for(int i=0; i < trees; i++)
{
newfield.set(i, newfield.get(i) + i);
}
int max = 0;
for(int i=0; i < trees; i++)
{
if(newfield.get(i)>max) max = newfield.get(i);
}
System.out.println(max + 1);
scan.close();
}
}