Method
func
(int[] arr, int n, int d, int h)
Source from the content-addressed store, hash-verified
| 19 | } |
| 20 | |
| 21 | public static void func(int[] arr, int n, int d, int h) { |
| 22 | int waterLevel = 0; |
| 23 | for (int i = 0; i < n; i++) { |
| 24 | if (arr[i] > 0) { |
| 25 | waterLevel += arr[i]; |
| 26 | } else if (arr[i] == 0) { |
| 27 | if (waterLevel <= d) { |
| 28 | waterLevel = 0; |
| 29 | } else { |
| 30 | waterLevel -= d; |
| 31 | } |
| 32 | |
| 33 | } |
| 34 | if (waterLevel > h) { |
| 35 | System.out.println("YES"); |
| 36 | return; |
| 37 | } |
| 38 | } |
| 39 | System.out.println("NO"); |
| 40 | } |
| 41 | } |
Tested by
no test coverage detected