Submission #873400

#TimeUsernameProblemLanguageResultExecution timeMemory
873400vjudge1Kas (COCI17_kas)C++17
0 / 100
86 ms99164 KiB
#include<bits/stdc++.h> using namespace std; const int N=1e5+7, inf=1e9+7; int n, a[N], s; int f[503][N/2]; int calc(int k, int diff) { if(diff>=N) return -inf; if(f[k][diff]!=-1) return f[k][diff]; int &ret=f[k][diff]; if(k==n){ if(diff==0) return 0; return -inf; } return ret=max({calc(k+1, diff), calc(k+1, diff+a[k])+a[k], calc(k+1, abs(diff-a[k]))+a[k]}); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("brocandy.inp", "r", stdin); // freopen("brocandy.out", "w", stdout); cin>>n; for(int i=0; i<n; i++) cin>>a[i], s+=a[i]; memset(f, -1, sizeof(f)); int ans=calc(0, 0); ans+=-ans+(s-ans); cout<<ans; }
#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...