Submission #182407

#TimeUsernameProblemLanguageResultExecution timeMemory
182407XmtosXKas (COCI17_kas)C++17
100 / 100
1317 ms395000 KiB
#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 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...