Submission #5492384


Source Code Expand

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

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);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N, ans = 0;
    	int[] A, B;
    	
        void solve(InputReader in, PrintWriter out) {
            // write your code here
        	N = in.nextInt();
        	A = new int[N];
        	B = new int[N];
        	for (int i = 0; i < N; ++i) {
        		A[i] = in.nextInt();
        		B[i] = in.nextInt();
        	}
        	
        	for (int i = N - 1; i >= 0; --i) {
        		int mul = (int) Math.ceil((A[i] + ans) / (double)B[i]);
        		ans += B[i]*mul - (A[i] + ans);
        	}
        	
        	out.print(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Submission Info

Submission Time
Task A - Multiple Array
User hatsujime
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2442 Byte
Status WA
Exec Time 233 ms
Memory 46728 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 2
AC × 9
WA × 9
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 WA 218 ms 45328 KB
02.txt WA 232 ms 46728 KB
03.txt WA 226 ms 45180 KB
04.txt WA 226 ms 40172 KB
05.txt WA 214 ms 43692 KB
06.txt WA 220 ms 44968 KB
07.txt AC 211 ms 42876 KB
08.txt WA 227 ms 44392 KB
09.txt AC 207 ms 43000 KB
10.txt WA 233 ms 38684 KB
11.txt AC 216 ms 40124 KB
12.txt AC 180 ms 44432 KB
13.txt WA 215 ms 38260 KB
14.txt AC 232 ms 41952 KB
15.txt AC 69 ms 18900 KB
16.txt AC 70 ms 19412 KB
s1.txt AC 70 ms 18004 KB
s2.txt AC 70 ms 19284 KB