Submission #1359096


Source Code Expand

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		sc.fill(A, B);

		int sum = 0;
		for (int i = 0; i < N; i++) {
			int index = N - i - 1;
			int mod = (sum + A[index]) % B[index];
			if (mod > 0) {
				sum += B[index] - mod;
			}
		}

		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Submission Info

Submission Time
Task A - Multiple Array
User YujiSoftware
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2659 Byte
Status WA
Exec Time 130 ms
Memory 24020 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 128 ms 19924 KB
02.txt WA 122 ms 22100 KB
03.txt WA 119 ms 22100 KB
04.txt WA 121 ms 24020 KB
05.txt WA 121 ms 21844 KB
06.txt WA 128 ms 21332 KB
07.txt AC 108 ms 19028 KB
08.txt WA 130 ms 22100 KB
09.txt AC 108 ms 22096 KB
10.txt WA 120 ms 20948 KB
11.txt AC 108 ms 18388 KB
12.txt AC 93 ms 21204 KB
13.txt WA 109 ms 21844 KB
14.txt AC 124 ms 22100 KB
15.txt AC 70 ms 22612 KB
16.txt AC 68 ms 21460 KB
s1.txt AC 67 ms 19540 KB
s2.txt AC 70 ms 20692 KB