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 long long mod=998244353;
int n,a[503],dp[500][200000],al;
int f(int x,int sum)
{
if(x==n)
{
if(sum==1e5)return 0;
else return -1e5;
}
if(dp[x][sum]!=-1)return dp[x][sum];
int num=-1e5;
num=max(num,f(x+1,sum+a[x])+a[x]);
num=max(num,f(x+1,sum-a[x]));
num=max(num,f(x+1,sum));
return dp[x][sum]=num;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("lemonade.in","r",stdin);
//freopen("lemonade.out","w",stdout);
memset(dp,-1,sizeof dp);
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
al+=a[i];
}
cout<<f(0,1e5)+((al-(f(0,1e5)*2)));
}
# | 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... |