Submission #1042911

#TimeUsernameProblemLanguageResultExecution timeMemory
1042911VMaksimoski008Kas (COCI17_kas)C++17
100 / 100
222 ms392448 KiB
#include <iostream> using namespace std; const int M = 1e5; int dp[505][2*M+5], v[505], n, S; int main() { cin >> n; for(int i=1; i<=n; i++) cin >> v[i], S += v[i]; for(int j=0; j<=2*M; j++) dp[0][j] = -1e9; dp[0][M] = 0; for(int i=1; i<=n; i++) { for(int j=0; j<=2*M; j++) { dp[i][j] = dp[i-1][j]; if(j + v[i] <= 2 * M) dp[i][j] = max(dp[i][j], dp[i-1][j+v[i]] + v[i]); if(j - v[i] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-v[i]] + v[i]); } } cout << S - dp[n][M] / 2 << '\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...