Created
May 22, 2018 02:57
-
-
Save redatawfik/43034119a408f0cc478aaf1fd29e9bf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Solution { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
int n = scan.nextInt(); | |
int[] arr = new int[n]; | |
for (int i = 0; i < arr.length; i++) { | |
arr[i] = scan.nextInt(); | |
} | |
int e = 0; | |
int d = 0; | |
int c = 0; | |
for (int i = 0; i < arr.length; i++) { | |
if ((c + e) < arr[i]) { | |
d += arr[i] - (c + e); | |
} | |
if(c > arr[i]){ | |
e += c - arr[i]; | |
}else if(c < arr[i]){ | |
e -= arr[i] - c; | |
if(e < 0) e = 0; | |
} | |
c = arr[i]; | |
} | |
System.out.println(d); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment