ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1048. Superlong Sums

please help me what Memory limit exceeded in test4 JAVA
Posted by Axmadjon 7 May 2014 11:31
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]);
    }
}