Submission #1306097


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 hhelibex
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2038 Byte
Status AC
Exec Time 292 ms
Memory 48400 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 262 ms 46704 KB
02.txt AC 292 ms 45056 KB
03.txt AC 262 ms 40928 KB
04.txt AC 289 ms 48400 KB
05.txt AC 267 ms 44424 KB
06.txt AC 286 ms 44436 KB
07.txt AC 240 ms 45296 KB
08.txt AC 261 ms 46216 KB
09.txt AC 266 ms 47644 KB
10.txt AC 276 ms 48048 KB
11.txt AC 249 ms 46464 KB
12.txt AC 211 ms 43700 KB
13.txt AC 264 ms 44876 KB
14.txt AC 265 ms 47556 KB
15.txt AC 76 ms 21332 KB
16.txt AC 68 ms 20180 KB
s1.txt AC 69 ms 21204 KB
s2.txt AC 68 ms 21332 KB