|
|
вернуться в форумI can't find my mistake Hi, Can you help me to find my mistake. In my opinion my solution is right but it fails on test 2. #include<iostream> #include<stdio.h> using namespace std; int n,m[21],can[100000],a,b,c=0; int abs_(int q) { if(q>=0)return q; if(q<0)return -q; } void solve() { int i,j; unsigned long long int p; p=0; for(p=i=0;i<n;p+=m[i++]); for(i=1;i<=p;i++) can[i]=0; can[0]=1; for(i=0;i<n;i++) for(j=p;j+1>0;j--) { if(can[j]) can[j+m[i]]=1; } for(i=p/2;i>1;i--) if(can[i]) { a=i; b=p-i; int g=a-b; c=abs_(g); printf("%u\n",c); return; } } int main() { int k; scanf("%u", &n); for(k=0;k<n;k++) scanf("%u", &m[k]); solve(); return 0; } |
|
|