Submission #170513

#TimeUsernameProblemLanguageResultExecution timeMemory
170513mdn2002Kas (COCI17_kas)C++14
100 / 100
1262 ms391928 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...