UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200954#3477. cycleJosephcheng100157ms5880kbC++11520b2024-01-14 11:50:202024-01-14 12:27:29

answer

#include<bits/stdc++.h>
#define MAXN 200005
#define LL long long
using namespace std;

LL n,sum,ans=-0x3f3f3f3f,all=0x3f3f3f3f,maxn=-0x3f3f3f3f;
LL a[MAXN],dp[MAXN],f[MAXN];

int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]),sum+=a[i],maxn=max(maxn,a[i]);
	for(int i=1;i<=n;i++)
		dp[i]=max(0*1ll,dp[i-1])+a[i],ans=max(ans,dp[i]);
	for(int i=1;i<=n;i++)
		f[i]=min(0*1ll,f[i-1])+a[i],all=min(all,f[i]);
	if(all==sum) all-=maxn;
	ans=max(ans,sum-all);
	printf("%lld",ans);
}

Details

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 1228kb

input:

1000
-6339 -3324 -4321 -2061 -1583 -4200 -6387 -4981 -3301 -8045 -5953 -1088 -137 -7984 -49 -8659 -5...

output:

-11

result:

ok single line: '-11'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1240kb

input:

1500
-2572 -9136 9846 7100 -2749 839 -398 -445 -7054 5896 -7591 -6726 -6591 -8623 -7579 6786 3298 -2...

output:

419168

result:

ok single line: '419168'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1252kb

input:

1999
-2564 4357 -1158 -1176 3381 -8734 -9781 -96 -3496 7789 -8518 -2471 -1745 -691 -1754 7776 -4606 ...

output:

220088

result:

ok single line: '220088'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1436kb

input:

10000
6287 -3856 -8285 -6088 2833 7818 -2058 6518 3917 -7335 -6646 -9760 -9089 -719 -5510 3907 5481 ...

output:

1462858

result:

ok single line: '1462858'

Test #5:

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

input:

50000
-6170 -9629 8254 8661 5765 -5163 -9761 -3824 -8598 -9277 9989 6545 -6520 -8179 7184 -7223 7748...

output:

1879166

result:

ok single line: '1879166'

Test #6:

score: 10
Accepted
time: 15ms
memory: 3548kb

input:

100000
5978 -6838 9793 -5652 -3320 -3517 4873 -5749 9349 9619 -6337 -1469 7822 -8087 2426 -3551 -141...

output:

3806528

result:

ok single line: '3806528'

Test #7:

score: 10
Accepted
time: 28ms
memory: 4724kb

input:

150000
-984 -6832 -8130 6518 8519 -2097 -8516 3034 9717 -4789 9988 6962 3648 6966 -1186 4620 7651 -5...

output:

4181297

result:

ok single line: '4181297'

Test #8:

score: 10
Accepted
time: 35ms
memory: 5424kb

input:

180000
-5306 -4462 -2014 -9755 -6513 4363 7957 -2987 -675 9313 -1417 5923 9282 8959 -488 -6141 -7996...

output:

3529609

result:

ok single line: '3529609'

Test #9:

score: 10
Accepted
time: 39ms
memory: 5880kb

input:

199999
2056 6238 6264 -7423 -8629 8380 2119 -1397 6663 5265 -6382 4428 7162 1340 3011 -9779 -1157 -8...

output:

6024945

result:

ok single line: '6024945'

Test #10:

score: 10
Accepted
time: 33ms
memory: 5880kb

input:

200000
6036 8112 7500 7279 -3731 -8368 -253 2644 7007 243 -3438 9912 3319 4281 -6915 -6104 5565 2926...

output:

4417899

result:

ok single line: '4417899'