You are viewing a single comment's thread. Return to all comments →
A java version:
public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int M = in.nextInt(); int[] arr = new int[N]; int a; int b; int k; while (M-- > 0) { a = in.nextInt() - 1; b = in.nextInt(); k = in.nextInt(); arr[a] += k; if (b < N) arr[b] -= k; } in.close(); long max = Long.MIN_VALUE; long sum = 0; for (int value : arr) { sum += value; if (sum > max) { max = sum; } } System.out.println(max); }
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
A java version: