QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65309 | #4591. Maxdifficent Group | triplem5ds# | AC ✓ | 15ms | 7420kb | C++23 | 2.0kb | 2022-11-29 18:04:47 | 2022-11-29 18:04:48 |
Judging History
answer
/// Brrrr Brrrr
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for(int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x,y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 1e5+5, LG = 18, MOD = (119 << 23) + 1;
const long double PI = acos(-1);
const long double EPS = 1e-7;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
using vi = vector<int>;
using pii = pair<int, int>;
int mxPrefix[N];
int mxSuffix[N];
int mnPrefix[N];
int mnSuffix[N];
int a[N], n;
void doWork() {
cin >> n;
int cur1 = 0, cur2 = 0;
mxPrefix[0] = LLONG_MIN;
mnPrefix[0] = LLONG_MAX;
for(int i = 1; i <= n; i++) {
cin >> a[i];
cur1 += a[i];
cur2 += a[i];
mxPrefix[i] = max(mxPrefix[i - 1], cur1);
mnPrefix[i] = min(mnPrefix[i - 1], cur2);
cur1 = max(cur1, 0ll);
cur2 = min(cur2, 0ll);
}
cur1 = 0, cur2 = 0;
mxSuffix[n + 1] = LLONG_MIN;
mnSuffix[n + 1] = LLONG_MAX;
for(int i = n; i >= 1; --i) {
cur1 += a[i];
cur2 += a[i];
mxSuffix[i] = max(mxSuffix[i + 1], cur1);
mnSuffix[i] = min(mnSuffix[i + 1], cur2);
cur1 = max(cur1, 0ll);
cur2 = min(cur2, 0ll);
}
ll ans = 0;
for(int i = 1; i + 1 <= n; i++) {
ans = max(ans, mxPrefix[i]-mnSuffix[i+1]);
ans = max(ans, mxSuffix[i+1]-mnPrefix[i]);
}
cout << ans << endl;
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
int t = 1;
// cin >> t;
while (t--) {
doWork();
}
return 0;
}
///Look at my code ya codeomk
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5476kb
input:
4 100 -30 -20 50
output:
150
result:
ok single line: '150'
Test #2:
score: 0
Accepted
time: 3ms
memory: 5380kb
input:
5 12 7 4 32 9
output:
46
result:
ok single line: '46'
Test #3:
score: 0
Accepted
time: 2ms
memory: 5356kb
input:
6 -5 10 -5 45 -20 15
output:
70
result:
ok single line: '70'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5460kb
input:
14 1 5 3 4 2 -4 -2 -6 -5 6 4 2 3 9
output:
41
result:
ok single line: '41'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3428kb
input:
2 0 -900000
output:
900000
result:
ok single line: '900000'
Test #6:
score: 0
Accepted
time: 5ms
memory: 6540kb
input:
59394 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 7ms
memory: 6816kb
input:
63744 -1 0 1 1 0 0 1 -1 -1 -1 -1 -1 1 1 1 -1 0 0 1 1 1 -1 1 -1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 -1 1 1 1 -1 1 -1 0 0 -1 -1 1 1 0 0 0 1 0 -1 -1 0 0 0 1 -1 0 1 0 0 1 -1 -1 0 0 -1 -1 1 0 1 0 1 0 -1 0 -1 1 1 -1 1 1 -1 1 -1 1 0 0 -1 1 1 0 0 -1 0 0 1 0 0 1 -1 1 0 1 0 -1 0 0 1 0 0 -1 0 0 0 -1 0 0 1 -1 -...
output:
475
result:
ok single line: '475'
Test #8:
score: 0
Accepted
time: 9ms
memory: 6920kb
input:
87255 4 -9 3 -3 -2 -2 3 10 -7 -10 -5 5 -9 -7 1 -1 10 0 -1 1 10 -9 -8 8 5 -8 2 -3 -7 7 -5 -3 3 -2 5 -1 -5 6 -2 8 3 0 -6 5 -10 5 0 -8 -3 -1 -7 -3 0 7 -4 5 -1 -5 -9 -2 8 7 6 -2 6 9 -2 6 10 3 10 -10 4 5 -9 0 -10 -9 -10 6 9 -5 -3 -7 -2 -4 6 4 7 -4 4 2 -8 -2 -4 3 2 -9 -4 9 3 8 -5 -1 8 -10 8 -3 -6 7 -1 8 -...
output:
5780
result:
ok single line: '5780'
Test #9:
score: 0
Accepted
time: 2ms
memory: 4328kb
input:
22859 123270 568778 416102 510776 597790 125263 860375 89550 16897 909046 124583 592535 32050 175429 993750 899188 863104 608753 724971 728319 82786 733737 923128 266621 57189 518044 556356 756193 408537 94718 998619 206034 125763 649241 204930 474150 57466 358193 153011 416494 753281 480726 927554 ...
output:
11402652338
result:
ok single line: '11402652338'
Test #10:
score: 0
Accepted
time: 2ms
memory: 6112kb
input:
33834 -514303 -172893 -206523 -8184 -343624 -208669 -690452 -17023 -342571 -830835 -999032 -533750 -822347 -62447 -85968 -172653 -485779 -40414 -37219 -564266 -427415 -565431 -197676 -911379 -238653 -602443 -410483 -122721 -921143 -764784 -355380 -23053 -510189 -547702 -165836 -672416 -12018 -966618...
output:
16851470332
result:
ok single line: '16851470332'
Test #11:
score: 0
Accepted
time: 3ms
memory: 5992kb
input:
38275 -999930 -999875 -999861 -999804 -999784 -999669 -999500 -999492 -999437 -999435 -999368 -999324 -999180 -999143 -999117 -999090 -999085 -999026 -998991 -998956 -998853 -998850 -998832 -998603 -998594 -998572 -998559 -998550 -998506 -998390 -998277 -998258 -998220 -998135 -998087 -997967 -99785...
output:
19123721387
result:
ok single line: '19123721387'
Test #12:
score: 0
Accepted
time: 7ms
memory: 6056kb
input:
37238 999909 999833 999825 999777 999746 999734 999700 999678 999636 999622 999616 999213 999117 999095 998985 998963 998939 998861 998771 998769 998739 998677 998636 998634 998531 998275 998224 998146 998046 997992 997955 997788 997735 997647 997629 997628 997490 997456 997230 997193 997118 996935 ...
output:
18615206654
result:
ok single line: '18615206654'
Test #13:
score: 0
Accepted
time: 5ms
memory: 6292kb
input:
43149 -140201 -501803 656742 -329686 -795682 -699585 891458 639773 -265403 -322470 587438 -291944 981542 -514447 -146704 158657 308640 -720314 -593447 93738 -837311 -528874 -298652 643385 -665241 124247 -263996 -251752 -777850 814558 134614 498228 23865 628783 856530 -100188 350276 685071 -635465 54...
output:
179476167
result:
ok single line: '179476167'
Test #14:
score: 0
Accepted
time: 6ms
memory: 7232kb
input:
100000 -157175 -347083 -932037 -545196 -659616 600072 -286127 -201837 -997799 -12057 -921128 -6769 -754129 -681225 -136294 -187918 -42011 -568716 -816662 -239977 -417282 -319395 -751876 -674830 -570340 -724210 -422603 -961907 -699371 -249593 -881886 -260367 -873171 -830607 -733352 -533789 -980129 -7...
output:
45189595250
result:
ok single line: '45189595250'
Test #15:
score: 0
Accepted
time: 2ms
memory: 5472kb
input:
15 1 5 3 4 2 -4 -2 -6 -5 6 4 2 -1 3 9
output:
40
result:
ok single line: '40'
Test #16:
score: 0
Accepted
time: 14ms
memory: 7324kb
input:
100000 -307691 -36043 -946036 -686424 -566905 -420198 -113847 -609649 764682 -193881 -899305 -860342 -940133 -759469 -230786 -994676 -867417 -152003 -282385 -447316 -276684 17745 766295 983080 -982977 -468861 -461817 -667312 -489521 -783625 578675 -335354 -112405 -319581 -731817 928193 -390912 17800...
output:
30112062436
result:
ok single line: '30112062436'
Test #17:
score: 0
Accepted
time: 6ms
memory: 7416kb
input:
100000 658278 533446 558630 629623 -652850 813489 22153 444342 -840819 398522 -844516 820768 120540 787858 601681 500489 737223 143950 30285 221094 831731 -51007 478262 958441 78095 997762 -856661 198549 912683 -982411 -332169 105654 926334 241928 776480 710775 373661 -569913 252078 -664734 934727 5...
output:
30206288025
result:
ok single line: '30206288025'
Test #18:
score: 0
Accepted
time: 5ms
memory: 7228kb
input:
100000 885843 211467 483777 880908 621629 672454 927665 373370 642637 831819 633521 705075 257622 884483 -629676 147436 793150 20749 25441 513181 991663 5396 556128 272223 -176491 797588 203690 547393 689786 651347 952385 369819 569653 423985 437025 232089 610489 165849 122185 514267 916720 900826 6...
output:
44970531802
result:
ok single line: '44970531802'
Test #19:
score: 0
Accepted
time: 15ms
memory: 7420kb
input:
100000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 10000...
output:
100000000000
result:
ok single line: '100000000000'
Test #20:
score: 0
Accepted
time: 11ms
memory: 7252kb
input:
100000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000000 -1000...
output:
100000000000
result:
ok single line: '100000000000'
Test #21:
score: 0
Accepted
time: 1ms
memory: 7416kb
input:
100000 4 -4 1 -1 0 -3 0 -3 0 -3 2 -4 3 -1 5 -2 5 0 5 -1 2 -4 3 -5 0 0 4 -2 3 -4 0 -3 1 -2 2 0 5 0 3 -1 0 0 2 -1 1 -1 2 -5 0 -1 4 -5 2 -3 4 -3 5 -3 3 -1 1 -4 1 -1 2 0 2 -2 3 -4 1 0 0 -4 1 -5 4 -5 4 -3 1 -2 0 -4 3 -1 3 -5 3 -2 4 -1 1 -5 1 -5 1 -1 3 0 0 -5 2 -2 0 0 4 -3 4 -4 5 -4 5 -2 1 -4 3 -2 2 0 3 0...
output:
1218
result:
ok single line: '1218'
Test #22:
score: 0
Accepted
time: 5ms
memory: 7244kb
input:
100000 444 -776 747 -387 326 -705 596 -986 625 -173 573 -752 339 -788 24 -189 223 -239 860 -759 28 -259 848 -149 944 -885 178 -606 304 -716 155 -368 874 -295 234 -845 458 -79 388 -380 772 -931 177 -544 847 -821 272 -590 284 -72 475 -243 202 -959 140 -414 11 -490 642 -536 254 -590 700 -767 140 -522 9...
output:
199837
result:
ok single line: '199837'
Test #23:
score: 0
Accepted
time: 14ms
memory: 7208kb
input:
100000 563179 -765819 495981 -386281 64392 -387302 906567 -344583 67639 -345773 148950 -341063 501073 -328845 101488 -67836 486919 -495483 56829 -599378 787063 -562824 863752 -997437 337554 -163114 292782 -520572 541560 -83900 710391 -781657 846568 -408331 756965 -734334 916044 -135468 855861 -78616...
output:
235574421
result:
ok single line: '235574421'
Test #24:
score: 0
Accepted
time: 11ms
memory: 7208kb
input:
100000 999972 -999998 999964 -999984 999958 -999976 999943 -999959 999938 -999943 999936 -999935 999923 -999927 999922 -999923 999918 -999920 999914 -999919 999900 -999908 999894 -999890 999892 -999882 999882 -999878 999873 -999877 999864 -999868 999856 -999866 999843 -999861 999841 -999860 999840 -...
output:
126507698
result:
ok single line: '126507698'
Test #25:
score: 0
Accepted
time: 9ms
memory: 7232kb
input:
100000 819007 547583 327217 565561 106362 217061 -716404 741630 716330 -532318 -813391 -759762 305113 68378 -71747 -75681 768967 507210 369676 732910 868066 -218819 -953407 -234699 -528639 -939234 -519895 578924 -878586 804895 -663060 -528491 407649 -475133 565787 -766258 4279 796578 -961305 -967104...
output:
479363935
result:
ok single line: '479363935'
Test #26:
score: 0
Accepted
time: 2ms
memory: 5384kb
input:
2 5 -5
output:
10
result:
ok single line: '10'
Test #27:
score: 0
Accepted
time: 14ms
memory: 7208kb
input:
100000 900492 -94287 647916 -472499 387598 -244045 548637 -470715 703434 -840232 780327 -938751 181813 -803823 338285 -110259 469229 -7153 989458 -682794 553431 -459339 508039 -902190 738709 -499557 802745 -700007 991945 -334004 685716 -4684 430924 -777909 639529 -854928 728391 -764633 318150 -56204...
output:
235760900
result:
ok single line: '235760900'
Test #28:
score: 0
Accepted
time: 14ms
memory: 7204kb
input:
100000 -627428 420466 -917762 -240450 331798 528644 322954 -502745 -594064 -395479 11990 -55727 -742498 866232 365932 570936 -263293 443873 -272003 206298 -354927 955584 498513 929006 713114 -836150 -455211 632018 955205 -834178 603075 620583 -452537 -764652 -165032 300257 318049 -693645 -926747 -11...
output:
475972764
result:
ok single line: '475972764'
Test #29:
score: 0
Accepted
time: 11ms
memory: 7416kb
input:
100000 621245 -388548 753158 -382036 801484 -518998 383594 -807989 778526 -319973 762327 -999766 957330 -92745 502789 -25156 16590 -523763 975479 -777715 495841 -253085 761863 -710609 274630 -682500 841358 -271571 910435 -875973 829495 -859571 73587 -201711 862216 -170246 306044 -998176 885361 -3504...
output:
196835955
result:
ok single line: '196835955'
Test #30:
score: 0
Accepted
time: 3ms
memory: 7328kb
input:
100000 826415 -708194 495107 822245 -906598 482345 890536 955971 161047 -564933 -122079 -220971 953744 -288088 -954937 270327 5628 -275426 770373 -743481 319230 266021 -930555 160686 384840 274418 -88338 -125910 -665842 949568 210027 501059 519298 -715316 537013 -823824 -724026 612112 823358 -881067...
output:
534000536
result:
ok single line: '534000536'
Test #31:
score: 0
Accepted
time: 4ms
memory: 7328kb
input:
100000 365678 -982871 212174 -707515 721288 -307315 282765 -652755 920072 -566337 169171 -848748 368393 -389425 788255 -63181 374239 -441060 435283 -424650 980896 -953562 219892 -172967 767984 -954012 826384 -372703 351353 -132649 315582 -542635 521757 -21445 850515 -385093 321702 -718169 66190 -129...
output:
259917617
result:
ok single line: '259917617'
Test #32:
score: 0
Accepted
time: 2ms
memory: 5468kb
input:
2 -5 5
output:
10
result:
ok single line: '10'
Test #33:
score: 0
Accepted
time: 0ms
memory: 5564kb
input:
4 100 -30 -20 50
output:
150
result:
ok single line: '150'
Test #34:
score: 0
Accepted
time: 2ms
memory: 5396kb
input:
5 12 7 4 32 9
output:
46
result:
ok single line: '46'
Test #35:
score: 0
Accepted
time: 2ms
memory: 5472kb
input:
6 -5 10 -5 45 -20 15
output:
70
result:
ok single line: '70'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3368kb
input:
5 0 0 0 0 0
output:
0
result:
ok single line: '0'
Test #37:
score: 0
Accepted
time: 3ms
memory: 5476kb
input:
2 1000000 100
output:
999900
result:
ok single line: '999900'