Submission #1338211
Source Code Expand
//Do what you can't. import java.io.*; import java.util.*; import java.math.BigInteger; public class Main { static long mod = (long)1e9 + 7; public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = in.nextInt(); long[] a = new long[n], b = new long[n]; for (int i = 0; i < n; i++) { a[i] = in.nextLong(); b[i] = in.nextLong(); } long c = 0; long[] sum = new long[n + 1]; for (int i = n - 1; i > -1; i--) { a[i] = a[i] + sum[i + 1]; if (a[i]%b[i]==0) continue; long temp = (a[i] / b[i] + 1) * b[i] - a[i]; c = c + temp; sum[i] = sum[i + 1] + temp; } w.println(c); w.close(); } static String rev(String s) { StringBuilder b = new StringBuilder(s); return b.reverse().toString(); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Submission Info
Submission Time | |
---|---|
Task | A - Multiple Array |
User | ashubeckham |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 3668 Byte |
Status | WA |
Exec Time | 114 ms |
Memory | 25300 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 114 ms | 21588 KB |
02.txt | AC | 112 ms | 22868 KB |
03.txt | AC | 112 ms | 23508 KB |
04.txt | AC | 111 ms | 24020 KB |
05.txt | AC | 111 ms | 23636 KB |
06.txt | AC | 109 ms | 23892 KB |
07.txt | AC | 95 ms | 23764 KB |
08.txt | AC | 112 ms | 23892 KB |
09.txt | AC | 92 ms | 21460 KB |
10.txt | AC | 111 ms | 21204 KB |
11.txt | WA | 104 ms | 21972 KB |
12.txt | AC | 88 ms | 21460 KB |
13.txt | WA | 107 ms | 25300 KB |
14.txt | AC | 103 ms | 19668 KB |
15.txt | AC | 68 ms | 21204 KB |
16.txt | AC | 68 ms | 18388 KB |
s1.txt | AC | 68 ms | 18260 KB |
s2.txt | AC | 68 ms | 19156 KB |