#ifndef EVAL
#include "homecoming.h"
#endif
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll reshay(int n, int k, deque<int> a, deque<int> b){
vector<ll> pa(n), pb(n), dp(n);
for(int i=0;i<n;i++){
pa[i] = a[i];
if(i) pa[i] += pa[i-1];
pb[i] = b[i];
if(i) pb[i] += pb[i-1];
}
ll mx = 0, res = 0;
for(int i=0;i<n;i++){
if(i >= k) mx = max(mx, dp[i - k] - pa[i - k] + pb[i - k]);
if(i + 1 >= k){
dp[i] = max(0ll, mx - pb[i] + pa[i - k + 1]);
}
res = max(res, dp[i]);
}
return res;
}
/*
1
3 2
40 80 100
140 0 20
*/
ll solve(int n, int k, int A[], int B[]){
deque<int> a, b;
ll res = 0;
for(int i=0;i<n;i++) a.push_back(A[i]), res += A[i];
for(int i=0;i<n;i++) b.push_back(B[i]), res -= B[i];
res = max(res, 0ll);
for(int i=0;i<n;i++){
res = max(res, reshay(n, k, a, b));
a.push_back(a.front()); a.pop_front();
b.push_back(b.front()); b.pop_front();
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
24396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |