Submission #1073883
Source Code Expand
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * @author Pavel Mavrin */ public class Main { private void solve() throws IOException { int n = nextInt(); long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); b[i] = nextInt(); } long res = 0; for (int i = n - 1; i >= 0; i--) { long q = -(a[i] + res); q %= b[i]; if (q < 0) q += b[i]; res += q; } out.println(res); } // ------------------ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; PrintWriter out = new PrintWriter(System.out); String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } public static void main(String[] args) throws IOException { new Main().run(); } private void run() throws IOException { solve(); out.close(); } }
Submission Info
Submission Time | |
---|---|
Task | A - Multiple Array |
User | pashka |
Language | Java8 (OpenJDK 1.8.0) |
Score | 300 |
Code Size | 1387 Byte |
Status | AC |
Exec Time | 270 ms |
Memory | 28956 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 | 261 ms | 28656 KB |
02.txt | AC | 262 ms | 28836 KB |
03.txt | AC | 262 ms | 28760 KB |
04.txt | AC | 268 ms | 27984 KB |
05.txt | AC | 260 ms | 28632 KB |
06.txt | AC | 261 ms | 28748 KB |
07.txt | AC | 254 ms | 28440 KB |
08.txt | AC | 251 ms | 28956 KB |
09.txt | AC | 250 ms | 28836 KB |
10.txt | AC | 257 ms | 28664 KB |
11.txt | AC | 254 ms | 28816 KB |
12.txt | AC | 229 ms | 28708 KB |
13.txt | AC | 254 ms | 28468 KB |
14.txt | AC | 270 ms | 28608 KB |
15.txt | AC | 95 ms | 8012 KB |
16.txt | AC | 95 ms | 8012 KB |
s1.txt | AC | 94 ms | 8144 KB |
s2.txt | AC | 95 ms | 8272 KB |