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

please help,EASY DP,BUT WHY WA at 1?
Posted by iostream 20 May 2010 22:37
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const long MAX = 2000000;

bool dp[MAX+1];

int main()
{

        int n;
        long k,sum=0,t;
        memset(dp,0,sizeof(dp));
        scanf("%d",&n);
        dp[0]=true;
        for(int i=0;i<n;i++)
        {
                scanf("%ld",&k);
                sum+=k;
                for(long j=sum/2;j>=0;j--)
                        if(dp[j]&&j+k<MAX/2)
                                dp[j+k]=true;
        }
        for(t=sum/2;dp[t]==false;t--);
        printf("%d\n",sum-2*t);
        system("pause");
        return 0;
}

Edited by author 20.05.2010 22:39