제출 #1227984

#제출 시각아이디문제언어결과실행 시간메모리
1227984Ghulam_JunaidHomecoming (BOI18_homecoming)C++20
0 / 100
1094 ms27716 KiB
#include <bits/stdc++.h>
// #include "homecoming.h"
using namespace std;

typedef long long ll;

ll solve(int n, int k, int *a, int *b){
    ll dp[2 * n + 10] = {};
    ll pa[2 * n + 10], pb[2 * n + 10];
    
    pa[0] = pb[0] = 0;
    for (int i = 1; i <= 2 * n; i ++){
        pa[i] = pa[i - 1] + a[(i - 1) % n];
        pb[i] = pb[i - 1] + b[(i - 1) % n];
    }

    ll ans = pa[n] - pb[n];
    for (int i = 1; i <= n; i ++){
        dp[i] = 0;
        ll mx = 0;
        for (int j = i + 1; j < i + n; j ++){
            dp[j] = dp[j - 1];
            if (j - k < i) continue;
            mx = max(mx, dp[j - k] - pa[j - k] + pb[j - k]);
            ll val = pa[i - k + 1] - pb[i];
            dp[j] = max(dp[j], mx + val);
        }
        ans = max(ans, dp[i + n - 1]);
    }
    return ans;
}

// int main(){
//     int a[3] = {40, 80, 100};
//     int b[3] = {140, 0, 20};
//     cout << solve(3, 2, a, b) << endl;
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...