#include<bits/stdc++.h> using namespace std; int Os[100200]; int main(){ int A,B,C,a,b,c; cin>>A>>B>>C; cin>>a>>b>>c; //A; for(int i=0;i<100100;i++){ Os[i]=INT_MAX; } int ma,mb,mc; ma = A-a; mb = B-b; mc = C-c; Os[a]=min(Os[a],0); Os[b]=min(Os[b],0); Os[c]=min(Os[c],0); if(a+b<=B){ Os[a+b]=min(Os[a+b],1); } if(a+c<=C){ Os[a+c]=min(Os[a+c],1); } if(b+c<=C){ Os[b+c]=min(Os[b+c],1); } if(a+b+c<=C){ Os[a+c+b]=min(Os[a+c+b],2); } if(a-mb>0){ Os[a-mb]=min(Os[a-mb],1); } else{ Os[0]=min(Os[0],1); } if(a-mc>0){ Os[a-mc]=min(Os[a-mc],1); } else{ Os[0]=min(Os[0],1); } if(b-ma>0){ Os[b-ma]=min(Os[b-ma],1); } else{ Os[0]=min(Os[0],1); } if(b-mc>0){ Os[b-mc]=min(Os[b-mc],1); } else{ Os[0]=min(Os[0],1); } if(c-mb>0){ Os[c-mb]=min(Os[c-mb],1); } else{ Os[0]=min(Os[0],1); } if(c-ma>0){ Os[c-ma]=min(Os[c-ma],1); } else{ Os[0]=min(Os[0],1); } if(a-mb-mc>0){ Os[a-mb-mc]=min(Os[a-mb-mc],2); } else{ Os[0]=min(Os[0],2); } if(b-ma-mc>0){ Os[b-ma-mc]=min(Os[b-ma-mc],2); } else{ Os[0]=min(Os[0],2); } if(c-ma-mb>0){ Os[c-ma-mb]=min(Os[c-ma-mb],2); } else{ Os[0]=min(Os[0],2); } if(a+b-mc<=B and a+b-mc>=0){ if(a>=mc or b>=mc or a+b<=B){ Os[a+b-mc]=min(Os[a+b-mc],2); } else{ Os[a+b-mc]=min(Os[a+b-mc],3); } } if(a+c-mb<=C and a+c-mb>=0){ if(a>=mb or c>=mb or a+c<=C){ Os[a+c-mb]=min(Os[a+c-mb],2); } else{ Os[a+c-mb]=min(Os[a+c-mb],3); } } if(b+c-ma<=C and b+c-ma>=0){ if(b>ma or c<ma or b+c<=C){ Os[b+c-ma]=min(Os[b+c-ma],2); } else{ Os[b+c-ma]=min(Os[b+c-ma],2); } } for(int i=0;i<=C;i++){ if(Os[i]==INT_MAX){ cout<<-1<<" "; } else{ cout<<Os[i]<<" "; } } cout<<"\n"; return 0; }
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #include<bits/stdc++.h> using namespace std; int Os[100200]; int main(){ int A,B,C,a,b,c; cin>>A>>B>>C; cin>>a>>b>>c; //A; for(int i=0;i<100100;i++){ Os[i]=INT_MAX; } int ma,mb,mc; ma = A-a; mb = B-b; mc = C-c; Os[a]=min(Os[a],0); Os[b]=min(Os[b],0); Os[c]=min(Os[c],0); if(a+b<=B){ Os[a+b]=min(Os[a+b],1); } if(a+c<=C){ Os[a+c]=min(Os[a+c],1); } if(b+c<=C){ Os[b+c]=min(Os[b+c],1); } if(a+b+c<=C){ Os[a+c+b]=min(Os[a+c+b],2); } if(a-mb>0){ Os[a-mb]=min(Os[a-mb],1); } else{ Os[0]=min(Os[0],1); } if(a-mc>0){ Os[a-mc]=min(Os[a-mc],1); } else{ Os[0]=min(Os[0],1); } if(b-ma>0){ Os[b-ma]=min(Os[b-ma],1); } else{ Os[0]=min(Os[0],1); } if(b-mc>0){ Os[b-mc]=min(Os[b-mc],1); } else{ Os[0]=min(Os[0],1); } if(c-mb>0){ Os[c-mb]=min(Os[c-mb],1); } else{ Os[0]=min(Os[0],1); } if(c-ma>0){ Os[c-ma]=min(Os[c-ma],1); } else{ Os[0]=min(Os[0],1); } if(a-mb-mc>0){ Os[a-mb-mc]=min(Os[a-mb-mc],2); } else{ Os[0]=min(Os[0],2); } if(b-ma-mc>0){ Os[b-ma-mc]=min(Os[b-ma-mc],2); } else{ Os[0]=min(Os[0],2); } if(c-ma-mb>0){ Os[c-ma-mb]=min(Os[c-ma-mb],2); } else{ Os[0]=min(Os[0],2); } if(a+b-mc<=B and a+b-mc>=0){ if(a>=mc or b>=mc or a+b<=B){ Os[a+b-mc]=min(Os[a+b-mc],2); } else{ Os[a+b-mc]=min(Os[a+b-mc],3); } } if(a+c-mb<=C and a+c-mb>=0){ if(a>=mb or c>=mb or a+c<=C){ Os[a+c-mb]=min(Os[a+c-mb],2); } else{ Os[a+c-mb]=min(Os[a+c-mb],3); } } if(b+c-ma<=C and b+c-ma>=0){ if(b>ma or c<ma or b+c<=C){ Os[b+c-ma]=min(Os[b+c-ma],2); } else{ Os[b+c-ma]=min(Os[b+c-ma],2); } } for(int i=0;i<=C;i++){ if(Os[i]==INT_MAX){ cout<<-1<<" "; } else{ cout<<Os[i]<<" "; } } cout<<"\n"; return 0; } |