ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200890 | #3477. cycle | 15523597526 | 100 | 73ms | 4372kb | C++11 | 572b | 2024-01-14 10:05:57 | 2024-01-14 12:15:32 |
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std ;
ll a[200005] , b[200005] , n , i , x , cnt , ans1 = LONG_LONG_MIN , ans2 = LONG_LONG_MAX ;
int main(){
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
cout.tie(nullptr) ;
cin >> n >> x ;
cnt += x ;
if(x>0){
a[1] = x ;
b[1] = x ;
}else {
a[1] = 0 ;
b[1] = 0 ;
}
for(i=2;i<=n;i++){
cin >> x ;
cnt += x ;
a[i] = max(a[i-1]+x,x) ;
ans1 = max(ans1,a[i]) ;
b[i] = min(b[i-1]+x,x) ;
ans2 = min(ans2,b[i]) ;
}
cout << max(ans1,cnt-ans2) ;
return 0 ;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1268kb
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: 1ms
memory: 1280kb
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: 1284kb
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: 1412kb
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: 5ms
memory: 2032kb
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: 4ms
memory: 2820kb
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: 15ms
memory: 3596kb
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: 15ms
memory: 4064kb
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: 17ms
memory: 4372kb
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: 16ms
memory: 4372kb
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'