QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708148 | #8057. Best Carry Player 4 | Wolam | WA | 38ms | 5768kb | C++17 | 1.5kb | 2024-11-03 19:52:08 | 2024-11-03 19:52:09 |
Judging History
answer
#include<bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
using ll = long long;
const int maxn = 5e5 + 10;
int n,a[maxn],b[maxn];
void solve(void)
{
cin>>n;
int suma=0,sumb=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
suma+=a[i];
}
for(int i=0;i<n;i++)
{
cin>>b[i];
sumb+=b[i];
}
if(suma>sumb)b[0]+=suma-sumb;
else a[0]+=sumb-suma;
int mxa=n-1,mxb=n-1,mia=0,mib=0;
while(mxa>=0&&!a[mxa])mxa--;
while(mxb>=0&&!b[mxb])mxb--;
if(mxa+mxb<n)
{
cout<<"0\n";
return;
}
int ans1=0;
for(int i=0;i<n;i++)
{
int t=min(a[i],b[n-i-1]);
if(t)
{
mia=min(i,mia);
mib=n-i-1;
}
ans1+=t;
a[i]-=t;
b[n-i-1]-=t;
}
int sum=0,ans2=0;
for(int i=0;i<=n;i++)
{
sum+=b[n-i-1];
int t=min(a[i],sum);
ans2+=t;
sum-=t;
}
if(ans2)
{
cout<<ans1+ans2<<'\n';
return;
}
mxa=mxb=n-1;
while(mxa>=0&&!a[mxa])mxa--;
while(mxb>=0&&!b[mxb])mxb--;
int ans=ans1+ans2;
if(mxa>mia||mxb>mib)
{
cout<<ans<<'\n';
return;
}
cout<<ans-1<<'\n';
}
signed main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
/*
1
10
0 0 3 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 3 3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5672kb
input:
5 2 1 2 3 4 3 1 0 1 0 1 0 4 1 0 0 1 1 1 1 1 5 123456 114514 1919810 233333 234567 20050815 998244353 0 0 0 10 5 3 5 3 2 4 2 4 1 5 9 9 8 2 4 4 3 5 3 0
output:
5 1 2 467900 29
result:
ok 5 number(s): "5 1 2 467900 29"
Test #2:
score: -100
Wrong Answer
time: 38ms
memory: 5768kb
input:
100000 5 0 1 1 1 1 0 0 1 0 0 5 0 0 0 0 0 1 1 1 0 0 5 0 0 2 1 1 0 2 1 0 1 5 0 0 0 0 0 1 2 1 0 0 5 0 1 0 1 1 0 0 1 1 1 5 2 0 0 0 1 1 0 0 0 3 5 2 0 0 1 1 0 2 1 1 1 5 0 0 0 0 2 0 0 0 0 1 5 0 0 0 0 0 0 1 1 0 0 5 4 0 0 0 0 0 0 0 1 0 5 0 0 0 0 1 2 1 1 0 0 5 0 2 3 0 0 0 0 0 1 0 5 1 1 1 0 1 1 0 1 0 1 5 0 0 0...
output:
2 0 4 0 3 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 3 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 2 2 2 0 3 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 2 1 2 0 3 4 0 2 5 0 2 1 0 0 0 3 2 3 0 2 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 2 1 1 0 2 0 0 2 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 1 0 2 2 3 0 1 2 0 1 1 ...
result:
wrong answer 76th numbers differ - expected: '1', found: '2'