Submission #1359100
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); long sum = 0; for (int i = 0; i < N; i++) { int index = N - i - 1; long 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 | 300 |
Code Size | 2661 Byte |
Status | AC |
Exec Time | 128 ms |
Memory | 22096 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
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 | 121 ms | 20180 KB |
02.txt | AC | 122 ms | 20180 KB |
03.txt | AC | 120 ms | 21972 KB |
04.txt | AC | 124 ms | 20180 KB |
05.txt | AC | 128 ms | 19796 KB |
06.txt | AC | 121 ms | 20052 KB |
07.txt | AC | 108 ms | 22096 KB |
08.txt | AC | 121 ms | 20436 KB |
09.txt | AC | 109 ms | 21972 KB |
10.txt | AC | 121 ms | 20052 KB |
11.txt | AC | 111 ms | 21076 KB |
12.txt | AC | 93 ms | 19796 KB |
13.txt | AC | 108 ms | 20052 KB |
14.txt | AC | 123 ms | 21076 KB |
15.txt | AC | 68 ms | 18132 KB |
16.txt | AC | 68 ms | 20692 KB |
s1.txt | AC | 68 ms | 19156 KB |
s2.txt | AC | 66 ms | 18132 KB |