-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapple_division.cpp
More file actions
52 lines (47 loc) · 794 Bytes
/
Copy pathapple_division.cpp
File metadata and controls
52 lines (47 loc) · 794 Bytes
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod(ll a,ll b)
{
if(a>b)
return a-b;
return b-a;
}
ll summation(vector<int>v)
{
ll sum=0;
for(auto i:v)
sum+=i;
return sum;
}
vector<int>subset;
ll mindiff=INT_MAX,d=0;
void search(vector<int>v,int k,int n)
{
if(k==n)
{
ll diff=mod(d-summation(subset),summation(subset));
mindiff=min(mindiff,diff);
return;
}
subset.push_back(v[k]);
search(v,k+1,n);
subset.pop_back();
search(v,k+1,n);
}
int main()
{
#ifndef DEBUG
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int n;
cin>>n;
vector<int>v(n);
for(auto &i:v)
cin>>i;
d=summation(v);
search(v,0,n);
cout<<mindiff;
return 0;
}