This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "homecoming.h"
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969ll
#define MAXN 4000013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N, K;
ll A[MAXN], B[MAXN];
ll pref[MAXN];
ll dp[MAXN][2][2];
ll ans;
ll range(int l, int r)
{
return pref[r + 1] - pref[l];
}
ll solve(int n, int k, int *a, int *b)
{
N = n; K = k;
FOR(i, 0, N)
{
A[i] = a[i];
B[i] = b[i];
B[i + N] = b[i];
}
FOR(i, 0, 2 * N)
{
pref[i + 1] = pref[i] + B[i];
}
FOR(i, 0, N)
{
FOR(j, 0, 2)
{
FOR(k, 0, 2)
{
dp[i][j][k] = -LLINF;
}
}
}
dp[0][0][0] = 0;
dp[0][1][1] = A[0] - range(0, K - 1);
FOR(i, 1, N)
{
ckmax(dp[i][1][1], dp[i - 1][1][1] + A[i] - (i + K - 1 >= N ? 0 : B[i + K - 1]));
ckmax(dp[i][1][1], dp[i - 1][0][1] + A[i] - range(i, min(N - 1, i + K - 1)));
ckmax(dp[i][1][0], dp[i - 1][1][0] + A[i] - B[i + K - 1]);
ckmax(dp[i][1][0], dp[i - 1][0][0] + A[i] - range(i, i + K - 1));
ckmax(dp[i][0][1], dp[i - 1][1][1]);
ckmax(dp[i][0][1], dp[i - 1][0][1]);
ckmax(dp[i][0][0], dp[i - 1][1][0]);
ckmax(dp[i][0][0], dp[i - 1][0][0]);
}
ans = 0;
FOR(i, 0, 2)
{
FOR(j, 0, 2)
{
ckmax(ans, dp[N - 1][i][j]);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |