// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2e6 + 10, mod = 1e9 + 7;
const ll inf = 1e18;
int a[maxn], b[maxn];
ll dp[maxn][2], A[maxn], B[maxn];
ll solve(int n, int k, int *a, int *b){
for(int i = 0; i < n; i++)
A[i] = a[i] - b[i];
ll sm = 0;
for(int i = 1; i <= k-1; i++)
sm+= a[n-i];
for(int i = 0; i < n; i++)
B[i] = -sm, sm+= a[i], sm-= a[(i + n - k + 1) % k];
ll ans = 0;
for(int w = 0; w < 2; w++){
if(w == 0)
dp[0][0] = 0, dp[0][1] = -inf;
else
dp[0][0] = -inf, dp[0][1] = A[0];
for(int i = 1; i < n; i++){
dp[i][1] = max(dp[i-1][1], dp[i-1][0]) + A[i];
dp[i][0] = max(dp[i-1][0], dp[i-1][1] + B[i]);
}
for(int w2 = 0; w2 < 2; w2++)
ans = max(ans, dp[n-1][w2] + ((w2 == 1 && w == 0) ? B[0] : 0));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
29432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |