Submission #611910

# Submission time Handle Problem Language Result Execution time Memory
611910 2022-07-29T08:36:43 Z amunduzbaev Homecoming (BOI18_homecoming) C++17
31 / 100
1000 ms 24392 KB
#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]);
			if(i) dp[i] = max(dp[i], dp[i-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 Correct 1 ms 212 KB Output is correct
# 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 Correct 1 ms 212 KB Output is correct
6 Correct 192 ms 660 KB Output is correct
7 Correct 216 ms 656 KB Output is correct
8 Correct 56 ms 504 KB Output is correct
9 Correct 232 ms 624 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 24392 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 Correct 1 ms 212 KB Output is correct
6 Correct 192 ms 660 KB Output is correct
7 Correct 216 ms 656 KB Output is correct
8 Correct 56 ms 504 KB Output is correct
9 Correct 232 ms 624 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Execution timed out 1088 ms 24392 KB Time limit exceeded
12 Halted 0 ms 0 KB -