-
Notifications
You must be signed in to change notification settings - Fork 12
/
1147.cpp
84 lines (49 loc) · 1.33 KB
/
1147.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <bits/stdc++.h>
#define ll long long
#define MAX 100100
using namespace std;
vector <ll > v;
map <pair<ll,ll>,ll>mp;
ll dp[503000];
ll mini;
ll as,bs;
#define BIT(n) (1LL<<(n))
int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/sameer/Documents/sameer/input.sam","r",stdin);
#endif
ios_base::sync_with_stdio(false);
ll i,j,k,n,m,t,cont,a,b;
cin >> t;
ll cases = t,ans;
while(t--){
v.clear();
mp.clear();
memset(dp,0,sizeof dp);
cin >> n ;
ll sum =0;
for(i=0;i <n;i++) {
cin >> k;
v.push_back(k);
sum+= k;
}
ll total = sum;
sum /= 2;
dp[0] =1;
ll one =1;
for(i =0;i < v.size();i++) {
for(j = sum;j >= v[i];j--) {
dp[j] = dp[j] | (dp[j-v[i]] << 1);
}
}
a = n/2,b = n-a;
for( j= sum+1 ;j >=0;j--){
// cout <<j <<" "<< f[j] <<" " << BIT(a) << " " << BIT(b) << endl;
if ((dp[j] & BIT(a)) || (dp[j] & BIT(b))) ;
ans = j; break;
}
cout << "Case " << cases-t << ": " << min(ans,total-ans) << " " << max(total-ans,ans) << endl;
}
return 0;
}