-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathChiefHopper.java
More file actions
30 lines (28 loc) · 652 Bytes
/
Copy pathChiefHopper.java
File metadata and controls
30 lines (28 loc) · 652 Bytes
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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[] = new int[n+1];
for(int i=1;i<=n;i++){
a[i]=sc.nextInt();
}
a[0]=0;
int curr=n;
int prev=n-1;
int energy=0;
int diff;
int add=0;
while(curr!=0){
diff=a[curr]-a[prev];
energy+=diff;
if(energy<0){
add=0-energy;
}
curr--;
prev--;
}
System.out.println(energy+add);
}
}