0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 04:58:49 +00:00
OI-codes/Luogu/problem/P2036/P2036.cpp
2021-06-30 21:48:54 +08:00

29 lines
488 B
C++

#include <bits/stdc++.h>
using namespace std;
struct {
int s, b;
} a[15];
int n, ans = 0x3f3f3f3f;
void dfs(int now, int s, int b) {
if (now > n) {
if (s == 1 && b == 0) return;
ans = min(abs(s - b), ans);
return;
}
dfs(now + 1, s * a[now].s, b + a[now].b);
dfs(now + 1, s, b);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].s >> a[i].b;
}
dfs(1, 1, 0);
cout << ans << endl;
return 0;
}