-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10576.cpp
75 lines (69 loc) · 1.18 KB
/
10576.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
#include <iostream>
#include <vector>
#include <cstdio>
#define foi( i , n , k)for(int i = n ; i < k ; ++i)
using namespace std;
void back(vector<int>temp,int &out,int x,int s,int d)
{
if(x<12)
{
temp[x]=s;
back(temp,out,x+1,s,d);
temp[x]=-d;
back(temp,out,x+1,s,d);
}
else
{
int m=0;
int ntemp=0;
foi( i, 0 ,5 )
{
// cout<<i<<" ";
if(ntemp<0)
return;
ntemp+=temp[i];
m+=temp[i];
}
// cout<<endl;
// cout<<" ntemp "<<ntemp<<endl;
if(ntemp>0)
return;
foi( i , 0 , 7 )
{
// cout<<i+5<<" ";
ntemp-=temp[i];
ntemp+=temp[i+5];
// cout<<ntemp<<" ntemp"<<endl;
if(ntemp>0)
return;
m+=temp[i];
// cout<<"m "<< m<<endl;
}
// cout<<endl;
// cout<<"final"<<endl;
if(m>out)
{
// cout<<"cambie "<<m<<" "<<out<<endl;
foi( i , 0 ,12)
// cout<<temp[i]<<" ";
// cout<<endl;
out=m;
}
}
}
int main()
{
int s,d;
vector<int> v(12);
while(scanf("%d%d",&s,&d)!=EOF)
{
int out=-1;
back(v,out,0,s,d);
if(out<=0){
printf("Deficit\n");
}
else
printf("%d\n",out);
}
return 0;
}