0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-18 07:31:58 +00:00
OI-codes/Luogu/P2036/P2036.cpp

30 lines
489 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;
}