제출 #1227947

#제출 시각아이디문제언어결과실행 시간메모리
1227947Ghulam_JunaidHomecoming (BOI18_homecoming)C++20
0 / 100
89 ms113732 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][k + 10]; for (int i = 0; i < 2 * n + 10; i ++) for (int j = 0; j < k + 10; j ++) dp[i][j] = -1e18; ll ans = 0; for (int i = 0; i < n; i ++) ans += a[i] - b[i]; dp[0][0] = dp[0][1] = 0; for (int i = 1; i <= 2 * n; i ++){ for (int j = 0; j <= k; j ++){ dp[i][j] = max(dp[i - 1][j + 1], dp[i - 1][j] - b[(i + j - 1) % n]) + a[(i - 1) % n] * (j == k); ans = max(ans, dp[i][j]); } } 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...