답안 #611894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
611894 2022-07-29T08:27:57 Z tengiz05 Homecoming (BOI18_homecoming) C++17
31 / 100
1000 ms 20476 KB
#include <bits/stdc++.h>

using i64 = long long;
using namespace std;

i64 solve(int n, int k, int *A, int *B) {
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        a[i] = A[i];
        b[i] = B[i];
    }
    i64 ans = accumulate(A, A + n, 0LL) - accumulate(B, B + n, 0LL);
    for (int i = 0; i < n; i++) {
        vector<i64> pre(n + 1);
        for (int i = 0; i < n; i++) {
            pre[i + 1] = pre[i] + b[i];
        }
        vector<i64> dp(n), keep(n);
        keep[0] = a[0] - pre[k];
        dp[0] = max(0LL, keep[0]);
        for (int i = 1; i < n; i++) {
            if (i + k <= n) {
                keep[i] = max(dp[i - 1] + a[i] - (pre[i + k] - pre[i]), keep[i - 1] + a[i] - b[i + k - 1]);
            }
            dp[i] = max(dp[i - 1], keep[i]);
        }
        rotate(a.begin(), a.begin() + 1, a.end());
        rotate(b.begin(), b.begin() + 1, b.end());
        ans = max(ans, dp[n - 1]);
    }
    
    return ans;
}

/*

1
3 2
40 80 100
140 0 20


*/
long long solve(int N, int K, int *A, int *B);

#ifndef EVAL

int main() {
  int T; assert(scanf("%d", &T) == 1);
  for(int t = 0; t < T; t++) {
    int N, K; assert(scanf("%d%d", &N, &K) == 2);
    int *A = new int[N];
    int *B = new int[N];
    for(int i = 0; i < N; i++) assert(scanf("%d", &A[i]) == 1);
    for(int i = 0; i < N; i++) assert(scanf("%d", &B[i]) == 1);
    printf("%lld\n", solve(N, K, A, B));
    delete[] A;
    delete[] B;
  }
  return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 68 ms 576 KB Output is correct
7 Correct 80 ms 596 KB Output is correct
8 Correct 33 ms 488 KB Output is correct
9 Correct 137 ms 576 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1010 ms 20476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 68 ms 576 KB Output is correct
7 Correct 80 ms 596 KB Output is correct
8 Correct 33 ms 488 KB Output is correct
9 Correct 137 ms 576 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Execution timed out 1010 ms 20476 KB Time limit exceeded
12 Halted 0 ms 0 KB -