UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208307#3774. Circular Platform Cluttershiruiheng100640ms94956kbC++111.3kb2024-08-02 09:51:582024-08-02 12:44:54

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//using LL = __int128
#define pi pair<ll, ll>
#define N 1111111
ll k, m, a[N], dp[N][11], f[N], n, ans;
int main(){
	scanf("%lld%lld%lld", &n, &m, &k);
	for(int i = 1 ; i <= n ; i++){
		scanf("%lld", a + i);
	}
	if(n <= 2000){
		for(int i = 1 ; i <= n ; i++)
			a[i] += a[i - 1];
		for(int i = 1 ; i <= n ; i++)
			for(int j = i + 1 ; j <= n ; j++)
				ans = max(ans, a[j] - a[i - 1] - (j - i + 1 + m - 1) / m * k);
		printf("%lld", ans);
		return 0;
	}
	if(k == 0){
		for(int i = 1 ; i <= n ; i++){
			f[i] = max(f[i - 1] + a[i], a[i]);
			ans = max(ans, f[i]);
		}
		printf("%lld", ans);
		return 0;
	}
	if(m == 1){
		for(int i = 1 ; i <= n ; i++)
			a[i] -= k;
		for(int i = 1 ; i <= n ; i++){
			f[i] = max(f[i - 1] + a[i], a[i]);
			ans = max(ans, f[i]);
		}
		printf("%lld", ans);
		return 0;
	}
	dp[0][0] = 0;
	for(int i = 1 ; i <= m ; i++)
		dp[0][i] = -0x3f3f3f3f3f3f3f3f;
	for(int i = 1 ; i <= n ; i++){
		dp[i][0] = max(0ll, dp[i - 1][m - 1] + a[i]);
		for(int j = 2 ; j < m ; j++)
			dp[i][j] = dp[i - 1][j - 1] + a[i];
		dp[i][1] = max(dp[i - 1][0], 0ll) + a[i] - k;
		for(int j = 0 ; j < m ; j++){
			ans = max(ans, dp[i][j]);
		}
	}
	printf("%lld", ans);
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 21ms
memory: 1216kb

input:

2000 3 16685558
-289282588 -61747468 -657707881 -34145392 -537924930 -406398379 -542751658 -75231580...

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 10
Accepted
time: 17ms
memory: 1220kb

input:

2000 9 54576364
255242838 -740596945 -246472080 950729683 -533760302 935128112 511618036 -775471790 ...

output:

329933931328

result:

ok 1 number(s): "329933931328"

Test #3:

score: 10
Accepted
time: 22ms
memory: 1220kb

input:

2000 9 73094302
512084424 67433847 974023247 550398283 943786443 -472874397 138837755 -744203670 539...

output:

332791924952

result:

ok 1 number(s): "332791924952"

Test #4:

score: 10
Accepted
time: 113ms
memory: 16828kb

input:

1000000 3 0
133466399 -867775767 963834867 775948067 -832740810 -713930238 -308186786 556371611 2949...

output:

647512117689

result:

ok 1 number(s): "647512117689"

Test #5:

score: 10
Accepted
time: 115ms
memory: 16828kb

input:

1000000 10 0
664925048 -566073238 877788649 -841053552 -308215965 -412748922 -840978942 -932597488 -...

output:

946593412159

result:

ok 1 number(s): "946593412159"

Test #6:

score: 10
Accepted
time: 112ms
memory: 16824kb

input:

1000000 1 383781667
797002344 -71828458 -547854034 543934687 917387704 832016545 -978766494 78233955...

output:

11338880406

result:

ok 1 number(s): "11338880406"

Test #7:

score: 10
Accepted
time: 11ms
memory: 10584kb

input:

100000 6 986672506
539233196 995762687 47061599 -854879180 810700777 -663371439 989492494 986856326 ...

output:

13786459060670

result:

ok 1 number(s): "13786459060670"

Test #8:

score: 10
Accepted
time: 7ms
memory: 10580kb

input:

100000 9 964197836
970180324 -694572429 985191372 -727965595 526258804 -617811687 -612003824 5067943...

output:

18656797316158

result:

ok 1 number(s): "18656797316158"

Test #9:

score: 10
Accepted
time: 110ms
memory: 94952kb

input:

1000000 10 944196936
-998994854 973754696 975675616 992984745 116889413 -987876256 917812370 -892363...

output:

196532701874927

result:

ok 1 number(s): "196532701874927"

Test #10:

score: 10
Accepted
time: 112ms
memory: 94956kb

input:

1000000 9 813298367
888006085 185751739 -970868688 -793265934 606885815 970133239 888746315 29012399...

output:

181821174468687

result:

ok 1 number(s): "181821174468687"