ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

I can't find my mistake
Posted by George_Georgiev 8 May 2009 04:01
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;
}