Adding some more judges, here and there.
[and.git] / NEERC / business / business_mb.java
blob541c0539efe40cfd8ce80ae43b7aa6cc417170c5
1 import java.io.*;
2 import java.util.Scanner;
4 public class business_mb implements Runnable {
5 public static void main(String[] args) {
6 new Thread(new business_mb()).start();
9 public void run() {
10 try {
11 final Scanner in = new Scanner(new FileReader("business.in"));
12 final PrintWriter out = new PrintWriter("business.out");
14 final int n = in.nextInt();
15 final int m = in.nextInt();
17 int ans = Integer.MAX_VALUE;
18 for (int i = 0; i < m; i++) {
19 final int u = in.nextInt();
20 final int d = in.nextInt();
21 final int x = (n * d) / (u + d) + 1;
22 final int cur = x * (u + d) - n * d;
23 ans = Math.min(ans, cur);
26 out.println(ans);
28 in.close();
29 out.close();
30 } catch (IOException e) {
31 e.printStackTrace();