This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=504;
int n,memo[N][200005],a[N];
int dp (int pos,int cur)
{
if (pos==n)
{
if (cur==1e5)
return 0;
return 1e9;
}
int &ret=memo[pos][cur];
if (ret!=-1)
return ret;
ret=dp(pos+1,cur)+a[pos];
ret=min(ret,dp(pos+1,cur-a[pos]));
ret=min(ret,dp(pos+1,cur+a[pos]));
return ret;
}
int main()
{
int sum=0;
cin >>n;
for (int i=0;i<n;i++)
cin >>a[i],sum+=a[i];
memset(memo,-1,sizeof memo);
int ans= dp(0,1e5);
cout <<ans+ (sum-ans)/2;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |