Submission #740911

#TimeUsernameProblemLanguageResultExecution timeMemory
740911dsyzKas (COCI17_kas)C++17
100 / 100
406 ms391724 KiB
#include <bits/stdc++.h> using namespace std; using ll = int; #define MAXN (200005) ll dp[505][MAXN]; int main() { ios_base::sync_with_stdio(false);cin.tie(0); ll N; cin>>N; ll arr[N]; ll total = 0; for(ll i = 0;i < N;i++){ cin>>arr[i]; total += arr[i]; } for(ll i = 0;i < N;i++){ for(ll j = 0;j < MAXN;j++){ dp[i][j] = -1e9; } } dp[0][100001] = 0; dp[0][100001 + arr[0]] = arr[0]; dp[0][100001 - arr[0]] = 0; for(ll i = 1;i < N;i++){ for(ll j = 0;j < MAXN;j++){ dp[i][j] = dp[i - 1][j]; if(j + arr[i] < MAXN) dp[i][j] = max(dp[i][j],dp[i - 1][j + arr[i]]); if(j - arr[i] >= 0) dp[i][j] = max(dp[i][j],dp[i - 1][j - arr[i]] + arr[i]); } } cout<<dp[N - 1][100001] + (total - 2 * dp[N - 1][100001])<<'\n'; }
#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...