QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#254607 | #4591. Maxdifficent Group | shura | WA | 3ms | 3936kb | C++20 | 2.3kb | 2023-11-18 13:24:16 | 2023-11-18 13:24:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
//kalo mines semua?
//-50 -4 -26 - 42
//-50 - (-4 - 26 - 42)
int main()
{
int n;
cin >> n;
int a[n + 5];
ll res = 0;
ll ares = 0;
ll semua = 0;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
semua += a[i];
}
int l = 1;
int r = 1;
int ml = 1;
int mr = 1;
ll sum = 0;
for(int i = 1; i <= n; i++)
{
if(sum + a[i] >= 0)
{
sum += a[i];
// if(l == r)
// {
// l = i; r = i;
// }
r = i;
}
else
{
sum = 0;
l = i;
r = i;
}
if(sum > res)
{
res = sum;
ml = l;
mr = r;
}
// cout<<i<<": "<<sum<<"\n";
}
if(res == 0)
{
res = max(abs(semua - a[1]), abs(semua - a[n]));
ares = max(ares, res);
}
else if(ml == 1 && mr == n)
{
// cout << res << endl;
res = max(abs(semua - a[1] - a[1]), abs(semua - a[n] - a[n]));
ares = max(ares, res);
}
else
{
ll minim = 0;
ll sum = 0;
for(int i = 1; i < ml; i++)
{
if(sum + a[i] > 0)
{
sum = 0;
}
else
{
sum += a[i];
}
minim = min(minim, sum);
}
sum = 0;
for(int i = mr + 1; i <= n; i++)
{
if(sum + a[i] > 0)
{
sum = 0;
}
else
{
sum += a[i];
}
minim = min(minim, sum);
}
res = abs(res - minim);
ares = max(ares, res);
}
l = 1;
r = 1;
ml = 1;
mr = 1;
sum = 0;
ll minim = 1e18;
for(int i = 1; i <= n; i++)
{
if(sum + a[i] < 0)
{
sum += a[i];
if(l == r)
{
l = i; r = i;
}
r = i;
}
else
{
sum = 0;
l = i;
r = i;
}
if(sum < minim)
{
// cout << l << " " << r << endl;
minim = sum;
ml = l;
mr = r;
}
}
// cout << ml << " " << mr << endl;
if(minim < 0)
{
sum = 0;
ll tambah = 0;
for(int j = 1; j < ml; j++)
{
if(sum + a[j] < 0)
{
sum = 0;
}
else
{
sum += a[j];
}
tambah = max(tambah, sum);
}
sum = 0;
for(int i = mr + 1; i <= n; i++)
{
if(sum + a[i] < 0)
{
sum = 0;
}
else
{
sum += a[i];
}
tambah = max(tambah, sum);
}
res = abs(tambah - minim);
ares = max(ares, res);
}
cout << res << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
4 100 -30 -20 50
output:
150
result:
ok single line: '150'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
5 12 7 4 32 9
output:
46
result:
ok single line: '46'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
6 -5 10 -5 45 -20 15
output:
70
result:
ok single line: '70'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3624kb
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: 0ms
memory: 3608kb
input:
2 0 -900000
output:
900000
result:
ok single line: '900000'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3860kb
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: -100
Wrong Answer
time: 3ms
memory: 3936kb
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:
514
result:
wrong answer 1st lines differ - expected: '475', found: '514'