#include "homecoming.h"
#include <bits/stdc++.h>
using namespace std;
void subtaskAsserts(int N, int K, int a[], int b[]) {
assert(N <= 500);
}
typedef long long int lint;
const int NMAX = 2000000;
const int VALMAX = 1000000000;
void asserts(int N, int K, int a[], int b[]) {
assert(1 <= K && K <= N && N <= NMAX);
for (int i = 0; i < N; ++ i) {
assert(0 <= a[i] && a[i] <= VALMAX);
assert(0 <= b[i] && b[i] <= VALMAX);
}
}
int A[2 * NMAX + 5], B[2 * NMAX + 5];
lint dp[2 * NMAX + 5];
lint solve(int N, int K, int a[], int b[]) {
asserts(N, K, a, b), subtaskAsserts(N, K, a, b);
// Copy and double a, b for internal use
for (int i = 0; i < N; ++ i) {
A[i] = a[i], A[N + i] = a[i];
B[i] = b[i], B[N + i] = b[i];
}
// Try to take all textbooks
lint ans = 0;
for (int i = 0; i < N; ++ i)
ans += A[i] - B[i];
// Fix a textbook we'll NOT take
for (int i = 0; i < N; ++ i) {
dp[i + N] = 0;
for (int j = i + N - 1; j >= i + 1; -- j) {
dp[j] = dp[j + 1];
lint cost = 0;
for (int k = j; k <= j + K - 2; ++ k)
cost -= B[k];
for (int k = j + K - 1; k < i + N; ++ k) {
cost += A[k - K + 1] - B[k];
dp[j] = max(dp[j], cost + dp[k + 1]);
}
}
ans = max(ans, dp[i + 1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
76 ms |
556 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
111 ms |
556 KB |
Output is correct |
5 |
Correct |
10 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
76 ms |
556 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
111 ms |
556 KB |
Output is correct |
5 |
Correct |
10 ms |
556 KB |
Output is correct |
6 |
Runtime error |
5 ms |
732 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
8608 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
76 ms |
556 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
111 ms |
556 KB |
Output is correct |
5 |
Correct |
10 ms |
556 KB |
Output is correct |
6 |
Runtime error |
5 ms |
732 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |