Submission #1073411


Source Code Expand

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
            }
            long extra = 0;
            for (int i = n - 1; i >= 0; --i) {
                long cur = a[i] + extra;
                long dest = (cur + b[i] - 1) / b[i] * b[i];
                extra += dest - cur;
            }
            out.println(extra);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Submission Info

Submission Time
Task A - Multiple Array
User Petr
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2142 Byte
Status AC
Exec Time 352 ms
Memory 28356 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 284 ms 27696 KB
02.txt AC 306 ms 27916 KB
03.txt AC 329 ms 27932 KB
04.txt AC 292 ms 27536 KB
05.txt AC 333 ms 27780 KB
06.txt AC 292 ms 27952 KB
07.txt AC 254 ms 27764 KB
08.txt AC 352 ms 27788 KB
09.txt AC 257 ms 28088 KB
10.txt AC 308 ms 27860 KB
11.txt AC 256 ms 27368 KB
12.txt AC 244 ms 27988 KB
13.txt AC 256 ms 28356 KB
14.txt AC 276 ms 27592 KB
15.txt AC 102 ms 8404 KB
16.txt AC 101 ms 8404 KB
s1.txt AC 102 ms 8404 KB
s2.txt AC 101 ms 8404 KB