UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200952#3477. cycleqiuqiu10049ms5844kbC++1.1kb2024-01-14 11:46:162024-01-14 12:27:15

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define m_p make_pair
#define t_s to_string
#define t_ll stoll
#define B break;
#define C continue;
#define R(x) return x;
#define K exit(0);
#define W while
#define F for
#define E else 
#define I if
#define EI else if
#define G(x) x=rd();
#define P printf
#define __lcm(a,b) (a/__gcd(a,b)*b)
#define X INT_MAX
#define N INT_MIN
int rd(){
	int x=0,f=1,ch=getchar();
	W(ch<'0'||ch>'9'){
		I(ch=='-') f=-1;
		ch=getchar();
	}
	W(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	R(x*f)
}
int arr[long(2e6)],sm[long(2e6)],smallsm[long(2e6)];
signed main()
{
	int x,s=0,iszheng=0,mxfu=N;
	G(x)
	F(int i=1;i<=x;i++){arr[i]=rd(),s+=arr[i];I(arr[i]<0){mxfu=max(mxfu,arr[i]);}E{iszheng=1;}}
	smallsm[1]=arr[1];
	sm[1]=arr[1];
	F(int i=2;i<=x;i++){
		sm[i]=max(sm[i-1]+arr[i],arr[i]);
		smallsm[i] = min(smallsm[i-1]+arr[i],arr[i]);
	}
	int mx=N,mn=X;
	F(int i=1;i<=x;i++){
		mx=max(mx,sm[i]);
		mn=min(mn,smallsm[i]);
	}
	printf("%lld\n",(iszheng?max(s-mn,mx):mxfu));
	R(0)
}

详细

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

Test #1:

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

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: 1188kb

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: 1204kb

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: 1388kb

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: 4ms
memory: 2324kb

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: 2ms
memory: 3496kb

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: 10ms
memory: 4676kb

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: 12ms
memory: 5376kb

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: 11ms
memory: 5844kb

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: 10ms
memory: 5844kb

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'