Skip to content

Commit da0af5a

Browse files
authored
Create cco08p5.cpp
1 parent 1f6cb45 commit da0af5a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

DMOJ/cco08p5.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
int N,K[101],C[101],tot;
4+
int main(){
5+
scanf("%d",&N);
6+
for(int i=1;i<=N;i++){
7+
scanf("%d %d",&K[i],&C[i]);
8+
tot += K[i]*C[i];
9+
}
10+
bitset<10000001> BS;
11+
BS.set(0);
12+
for(int i=1;i<=N;i++){
13+
int copia = K[i];
14+
vector<int> pot;
15+
for(int j = 0;(1 << j) <= K[i];j++){
16+
if(copia - (1 << j) > 0){
17+
pot.push_back((1 << j));
18+
copia -= (1 << j);
19+
}
20+
}
21+
pot.push_back(copia);
22+
for(int j : pot){
23+
BS |= BS << (C[i]*j);
24+
}
25+
}
26+
int best = tot;
27+
for(int v = 0;v<=tot;v++){
28+
if(BS[v] == 1){
29+
best = min(best, abs(tot - 2*v) );
30+
}
31+
}
32+
printf("%d\n",best);
33+
return 0;
34+
}

0 commit comments

Comments
 (0)