Submission #1042915

# Submission time Handle Problem Language Result Execution time Memory
1042915 2024-08-03T14:39:27 Z VMaksimoski008 Kas (COCI17_kas) C++17
100 / 100
231 ms 392500 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 j=0; j<=2*M; j++) dp[0][j] = -1e9;
    dp[0][M] = 0;

    for(int i=1; i<=n; i++) {
        cin >> v[i]; S += v[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 time Memory Grader output
1 Correct 6 ms 9052 KB Output is correct
2 Correct 7 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9052 KB Output is correct
2 Correct 5 ms 8892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9052 KB Output is correct
2 Correct 5 ms 9644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10548 KB Output is correct
2 Correct 7 ms 11360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11356 KB Output is correct
2 Correct 6 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28508 KB Output is correct
2 Correct 20 ms 32344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 36444 KB Output is correct
2 Correct 24 ms 40332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 157520 KB Output is correct
2 Correct 117 ms 196944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 235860 KB Output is correct
2 Correct 193 ms 314192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 353216 KB Output is correct
2 Correct 231 ms 392500 KB Output is correct