Submission #1042911

# Submission time Handle Problem Language Result Execution time Memory
1042911 2024-08-03T14:37:43 Z VMaksimoski008 Kas (COCI17_kas) C++17
100 / 100
222 ms 392448 KB
#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 time Memory Grader output
1 Correct 5 ms 9052 KB Output is correct
2 Correct 5 ms 9064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9048 KB Output is correct
2 Correct 5 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9052 KB Output is correct
2 Correct 5 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10588 KB Output is correct
2 Correct 7 ms 11336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11196 KB Output is correct
2 Correct 7 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 28508 KB Output is correct
2 Correct 18 ms 32384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 36440 KB Output is correct
2 Correct 23 ms 40132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 157624 KB Output is correct
2 Correct 109 ms 196888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 235860 KB Output is correct
2 Correct 187 ms 314156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 353320 KB Output is correct
2 Correct 222 ms 392448 KB Output is correct