Submission #944016

# Submission time Handle Problem Language Result Execution time Memory
944016 2024-03-12T06:35:08 Z TAhmed33 Homecoming (BOI18_homecoming) C++17
0 / 100
30 ms 31064 KB
#include <bits/stdc++.h>
#include "homecoming.h"
using namespace std;
typedef long long ll;
const int MAXN = 4e6 + 25;
ll dp[MAXN], pref_a[MAXN], pref_b[MAXN];
ll solve (int n, int k, int *A, int *B) {
    for (int i = 0; i < 2 * n; i++) {
        pref_a[i] = pref_b[i] = dp[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        pref_a[i] = A[i] + (i == 0 ? 0 : pref_a[i - 1]);
    }
    for (int i = 0; i < n + k; i++) {
        pref_b[i] = B[i % k] + (i == 0 ? 0 : pref_b[i - 1]);
    }
    ll ret = 0, cur = 0;
    for (int i = 0; i < n; i++) {
        dp[i] = pref_a[i] - pref_b[i + k - 1] + cur;
        if (i) dp[i] = max(dp[i], dp[i - 1]);
        else dp[i] = max(dp[i], 0ll);
        cur = max(cur, dp[i] - pref_a[i] + pref_b[i]);
        ret = max(ret, dp[i]);
    }
    cur = 0;
    for (int i = 0; i < n; i++) {
        dp[i] = pref_a[i] - pref_b[min(n - 1, i + k - 1)] + cur;
        if (i) dp[i] = max(dp[i], dp[i - 1]);
        cur = max(cur, dp[i] - pref_a[i] + pref_b[i]);
    }
    ret = max(ret, dp[n - 1]);
    return ret;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 31064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -