-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
36 lines (29 loc) ยท 1.02 KB
/
Main.java
File metadata and controls
36 lines (29 loc) ยท 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package BruteForce.P2961;
import java.io.*;
import java.util.StringTokenizer;
public class Main {
static int N, ans = 1000000000;
static int[][] sb;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/BruteForce/P2961/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
sb = new int[N][2];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
sb[i][0] = Integer.parseInt(st.nextToken());
sb[i][1] = Integer.parseInt(st.nextToken());
}
for (int i = 1; i < 1<<N; i++) {
int S = 1, B = 0;
for (int j = 0; j < N; j++) {
if ((i & 1<<j) > 0) {
S *= sb[j][0];
B += sb[j][1];
}
}
ans = Math.min(ans, Math.abs(S-B));
}
System.out.println(ans);
}
}