Last active
August 18, 2018 14:56
-
-
Save ytnk531/084b9ef3bb268f0a305e0825384a88f4 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
public class ArrayManupilation { | |
static long arrayManipulation(int n, int[][] queries) { | |
long[] arr = new long[n+1]; | |
int a, b, k; | |
for (int [] query : queries) { | |
a = query[0]; | |
b = query[1]; | |
k = query[2]; | |
arr[a] += k; | |
if (b+1 <= n) arr[b+1] -= k; | |
} | |
long max = 0, x = 0; | |
for (int i=1 ;i<=n;i++) { | |
x += arr[i]; | |
if (max < x) { | |
max=x; | |
} | |
} | |
return max; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment