Submission #4057342


Source Code Expand

Copy
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] h = new int[N];
		int sum = 0;
		for(int i = 0; i < N; i++){
			h[i] = scanner.nextInt();
			sum += h[i];
		}
		int tmp = h[0];
		int count = 0;
		while(sum > 0){
			for(int i = 0; i < N-1; i++){
				if(h[i] == 0 && h[i+1] != 0){
					count++;
				}
			}

			for(int i = 0; i < N; i++){
				if(h[i] != 0){
					h[i] -= 1;
					sum -= 1;
				}
			}
		}
		System.out.println(count+tmp);
 	}
}

Submission Info

Submission Time
Task C - Grand Garden
User rmkt
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 586 Byte
Status
Exec Time 101 ms
Memory 22996 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 300 / 300 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 93 ms 20560 KB
02.txt 96 ms 19668 KB
03.txt 93 ms 18896 KB
04.txt 92 ms 19284 KB
05.txt 93 ms 21588 KB
06.txt 98 ms 21332 KB
07.txt 95 ms 21204 KB
08.txt 96 ms 19796 KB
09.txt 97 ms 18644 KB
10.txt 98 ms 22996 KB
11.txt 99 ms 18900 KB
12.txt 98 ms 21460 KB
13.txt 97 ms 21844 KB
14.txt 99 ms 19024 KB
15.txt 101 ms 20688 KB
16.txt 99 ms 19412 KB
s1.txt 92 ms 19156 KB
s2.txt 92 ms 20820 KB
s3.txt 92 ms 19796 KB