Adding some more judges, here and there.
[and.git] / NEERC / business / business_gk.java
blobd94941b42a34860d931b83ea8141536bbcbffc57
1 import java.util.*;
2 import java.io.*;
4 class business_gk {
5 static Scanner in;
6 static PrintWriter out;
8 void run() throws IOException {
9 int n = in.nextInt();
10 int m = in.nextInt();
12 int min = Integer.MAX_VALUE;
13 for (int i = 0; i < m; i++) {
14 int u = in.nextInt();
15 int d = in.nextInt();
17 int x = d * n / (u + d) + 1;
18 min = Math.min(min, (u + d) * x - d * n);
21 out.println(min);
24 public static void main(String[] args) throws Exception {
25 in = new Scanner(new File("business.in"));
26 out = new PrintWriter("business.out");
28 new business_gk().run();
30 in.close();
31 out.close();