Submission #1042910

#TimeUsernameProblemLanguageResultExecution timeMemory
1042910VMaksimoski008Kas (COCI17_kas)C++17
100 / 100
220 ms392524 KiB
#include <iostream> using namespace std; const int M = 1e5 + 5; int dp[505][2*M+5], v[505]; int main() { int n, S = 0; 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'; 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...