QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722659 | #6443. Windblume Festival | IsacBieber# | WA | 146ms | 5760kb | C++23 | 1.1kb | 2024-11-07 19:50:16 | 2024-11-07 19:50:16 |
Judging History
answer
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<":"<<x<<"\n"
using namespace std;
using ll = long long;
using pii = pair <int,int>;
const int N = 1e6 + 5, MOD = 1e9 + 7;
int n;
ll a[N], s[N];
void solve()
{
cin>>n;
bool flag = 0;
ll g = 0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
g += abs(a[i]);
if(a[i]<0) flag = 1;
s[i] = s[i-1] + a[i];
}
if(n==1) cout<<a[1]<<'\n';
else if(n==2) cout<<max(a[2]-a[1],a[1]-a[2])<<'\n';
else
{
if(flag) cout<<g<<'\n';
else
{
ll ans = -1e18;
for(int i=1;i<=n;i++)
{
if(i==1)
{
ans = max(ans,a[n]-(a[1]-(s[n-1]-a[1])));
}
else
{
ans = max(ans,a[i-1]-(a[i]-(s[n]-s[i])-s[i-2]));
}
}
cout<<ans<<'\n';
}
}
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5752kb
input:
5 4 1 -3 2 -4 11 91 66 73 71 32 83 72 79 84 33 93 12 91 66 73 71 32 83 72 79 84 33 33 93 13 91 66 73 71 32 83 72 79 84 33 33 33 93 1 0
output:
10 713 746 779 0
result:
ok 5 number(s): "10 713 746 779 0"
Test #2:
score: 0
Accepted
time: 104ms
memory: 5712kb
input:
1000000 1 2 1 -2 1 1 1 -1 1 2 1 1 1 2 1 -2 1 -2 1 2 1 1 1 1 1 2 1 2 1 2 1 -2 1 -2 1 0 1 2 1 1 1 -1 1 0 1 -2 1 0 1 1 1 1 1 -2 1 -2 1 2 1 1 1 2 1 1 1 1 1 0 1 2 1 0 1 -1 1 -1 1 -2 1 -2 1 0 1 -2 1 0 1 1 1 -1 1 2 1 0 1 -2 1 -2 1 0 1 1 1 -1 1 -2 1 -1 1 0 1 -1 1 -1 1 -1 1 -1 1 1 1 2 1 0 1 0 1 -2 1 2 1 2 1 ...
output:
2 -2 1 -1 2 1 2 -2 -2 2 1 1 2 2 2 -2 -2 0 2 1 -1 0 -2 0 1 1 -2 -2 2 1 2 1 1 0 2 0 -1 -1 -2 -2 0 -2 0 1 -1 2 0 -2 -2 0 1 -1 -2 -1 0 -1 -1 -1 -1 1 2 0 0 -2 2 2 -1 2 -2 -1 -2 -1 -2 2 -1 -1 0 -2 0 0 0 1 1 2 1 -1 0 -2 1 2 1 1 0 1 2 -2 -1 -1 0 -2 2 2 1 0 -1 0 -1 0 1 -2 2 1 -2 -2 0 -1 1 -1 2 -2 2 1 1 2 0 2...
result:
ok 1000000 numbers
Test #3:
score: 0
Accepted
time: 146ms
memory: 5640kb
input:
1000000 1 -182188011 1 -889401027 1 -379434063 1 -731536137 1 632523155 1 837208235 1 192807861 1 -162604370 1 963735146 1 736725265 1 -70315400 1 659481275 1 217883785 1 -396219883 1 653358757 1 -489133046 1 412498823 1 -210628961 1 -137310415 1 849916587 1 -50143945 1 -509463528 1 105005776 1 7382...
output:
-182188011 -889401027 -379434063 -731536137 632523155 837208235 192807861 -162604370 963735146 736725265 -70315400 659481275 217883785 -396219883 653358757 -489133046 412498823 -210628961 -137310415 849916587 -50143945 -509463528 105005776 738262345 352827098 391146170 108054338 601933024 -705538291...
result:
ok 1000000 numbers
Test #4:
score: 0
Accepted
time: 86ms
memory: 5632kb
input:
666685 1 0 2 2 -1 1 2 1 2 1 -1 2 -2 2 1 0 2 -1 -2 2 2 -1 2 0 1 2 2 -1 1 1 2 1 1 1 1 2 0 2 2 1 0 2 0 2 2 -1 2 1 1 1 -1 1 -2 1 2 2 -1 0 2 -2 1 2 -2 -2 2 0 -1 1 -2 1 2 1 2 2 -1 -1 1 1 1 -2 1 2 2 -2 1 2 2 1 2 0 -2 1 -1 1 0 1 2 1 -2 2 2 0 1 -1 2 0 0 2 2 -2 2 -2 0 1 -2 1 1 2 2 0 1 -2 1 -1 2 1 -1 2 1 -2 2 ...
output:
0 3 2 2 -1 4 0 1 3 1 3 1 0 1 2 1 2 3 1 -1 -2 2 1 3 0 1 -2 2 2 0 1 -2 2 3 1 2 -1 0 2 -2 2 -1 0 4 2 -2 1 2 -2 -1 2 3 2 -2 3 4 2 2 -2 1 2 3 3 2 2 2 0 -2 2 1 1 0 2 -1 2 0 0 2 1 2 4 1 1 4 -2 -1 3 1 0 1 1 0 -2 2 1 2 2 1 2 -2 0 2 2 1 2 -1 0 -2 0 -1 2 0 3 1 0 -1 0 1 2 0 -1 1 -1 2 0 1 -1 -1 -2 1 0 2 1 -2 2 2...
result:
ok 666685 numbers
Test #5:
score: 0
Accepted
time: 126ms
memory: 5676kb
input:
666588 1 877229937 1 -790704201 2 932859032 656440170 1 -192529503 2 94528196 817385616 1 13901525 1 340254741 1 -685072067 2 549059935 448603339 2 675680588 -933313073 2 370439701 -907173091 2 -602257809 -804844783 2 627233219 -171938196 1 -643067959 2 -525280817 -454814822 1 557964767 1 -667401143...
output:
877229937 -790704201 276418862 -192529503 722857420 13901525 340254741 -685072067 100456596 1608993661 1277612792 202586974 799171415 -643067959 70465995 557964767 -667401143 212380490 596566747 41930382 -581445120 613463693 -594232733 -641051872 1766315648 143281260 1111011274 -534042370 854561349 ...
result:
ok 666588 numbers
Test #6:
score: -100
Wrong Answer
time: 75ms
memory: 5760kb
input:
499844 3 -1 -1 -2 2 1 1 1 1 3 2 1 2 1 1 3 1 2 -2 1 -1 3 2 2 2 1 -2 3 -2 -2 -1 3 1 -1 -2 3 -2 1 2 1 2 2 0 0 1 -1 2 -2 0 3 -1 -1 0 1 2 3 2 -1 -1 2 -2 1 2 2 2 1 0 3 0 2 -1 3 0 0 0 1 -2 1 -2 3 2 1 2 2 -2 2 2 0 -1 2 0 -2 1 -2 1 1 2 -1 1 2 -2 2 3 2 2 -2 3 -2 -2 -1 1 -2 1 2 3 -2 -2 1 1 2 2 2 1 3 -1 0 2 3 0...
output:
4 0 1 3 1 5 -1 2 -2 5 4 5 2 0 -1 2 2 2 4 3 0 0 3 0 -2 -2 3 4 1 2 -2 1 2 4 6 5 -2 2 5 2 1 3 3 2 5 -1 6 1 3 3 -1 4 1 -2 2 0 0 3 2 3 0 5 5 -2 3 1 0 4 -2 2 1 0 1 2 4 4 -1 5 3 1 -2 1 5 2 3 0 1 4 5 0 2 0 0 0 0 0 2 4 -1 3 4 0 0 1 2 4 6 2 5 4 3 2 2 -1 -2 2 4 1 1 0 1 4 5 3 1 5 6 3 3 1 1 2 4 2 0 4 1 2 -1 2 -1...
result:
wrong answer 1st numbers differ - expected: '2', found: '4'