Submission #732242

# Submission time Handle Problem Language Result Execution time Memory
732242 2023-04-28T19:22:08 Z blackslex Kas (COCI17_kas) C++17
90 / 100
156 ms 87268 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 505, M = 1e5 + 5;
int n, ans, a[N], dp[N][M];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i];
    for (int i = 1; i <= n; i++) {
        for (int j = M - 1; j >= 1; j--) if (dp[i - 1][j]) dp[i][j + a[i]] = max(dp[i][j + a[i]], dp[i - 1][j] + a[i]), dp[i][abs(a[i] - j)] = max(dp[i][abs(a[i] - j)], dp[i - 1][j] + a[i]), dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        dp[i][a[i]] = max({dp[i][a[i]], dp[i - 1][0] + a[i], dp[i - 1][a[i]]});
    }
    printf("%d", ans - (dp[n][0] >> 1));
}

Compilation message

kas.cpp: In function 'int main()':
kas.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
kas.cpp:10:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i];
      |                                  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 316 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 564 KB Output is correct
2 Correct 8 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 632 KB Output is correct
2 Correct 6 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 16596 KB Output is correct
2 Correct 34 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 18536 KB Output is correct
2 Correct 99 ms 23324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 40944 KB Output is correct
2 Correct 156 ms 87268 KB Output is correct