|
|
back to boardplease help me what Memory limit exceeded in test4 JAVA import java.util.Scanner; public class _1048 { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); int n, ind, i; n = s.nextInt(); int[] a = new int[n]; int[] b = new int[n]; int[] res = new int[n]; for (i = 0; i < n; i++) { a[i] = s.nextInt(); b[i] = s.nextInt(); } for (i = n - 1; i >= 1; i--) { ind = (a[i] + b[i]) / 10; if (ind > 0) { res[n - i] = ind; res[n - i - 1] += (a[i] + b[i]) % 10; } else res[n - 1 - i] += a[i] + b[i]; if (res[n - i - 1] >= 10) { res[n - i] += res[n - i - 1] / 10; res[n - i - 1] = res[n - i - 1] % 10; } } res[n - 1] += a[0] + b[0]; for (i = n - 1; i > -1; i--) System.out.print(res[i]); } } |
|
|