Submission #1306123


Source Code Expand

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(BufferedReader in) throws IOException {
        int N = Integer.parseInt(in.readLine());
        long[] A = new long[N];
        long[] B = new long[N];
        for (int i = 0; i < N; ++i) {
            String[] s = in.readLine().split(" ");
            A[i] = Long.parseLong(s[0]);
            B[i] = Long.parseLong(s[1]);
        }

        long ans = 0;
        for (int i = N - 1; i >= 0; --i) {
            A[i] += ans;
            long r = A[i] % B[i];
            if (r > 0) {
                ans += B[i] - r;
            }
        }
        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) throws IOException {
        long S = System.currentTimeMillis();

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        new Main().solve(in);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Submission Info

Submission Time
Task A - Multiple Array
User unirita135
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2038 Byte
Status AC
Exec Time 296 ms
Memory 48304 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 18
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 282 ms 45040 KB
02.txt AC 268 ms 48064 KB
03.txt AC 294 ms 44784 KB
04.txt AC 266 ms 45636 KB
05.txt AC 293 ms 43564 KB
06.txt AC 278 ms 45896 KB
07.txt AC 241 ms 44404 KB
08.txt AC 285 ms 42360 KB
09.txt AC 267 ms 46080 KB
10.txt AC 296 ms 44428 KB
11.txt AC 265 ms 48304 KB
12.txt AC 211 ms 45096 KB
13.txt AC 260 ms 47996 KB
14.txt AC 276 ms 43380 KB
15.txt AC 70 ms 17108 KB
16.txt AC 69 ms 21076 KB
s1.txt AC 70 ms 19156 KB
s2.txt AC 70 ms 21204 KB