We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f6cb45 commit da0af5aCopy full SHA for da0af5a
DMOJ/cco08p5.cpp
@@ -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
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