QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#657751 | #8057. Best Carry Player 4 | realman | WA | 58ms | 5888kb | C++14 | 760b | 2024-10-19 15:24:00 | 2024-10-19 15:24:02 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e5+10;
int n,T;ll a[N],b[N];
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int maxx=0,maxx1=0;ll s=0,s1=0;
for(int i=0;i<n;i++)
scanf("%lld",&a[i]),maxx=(a[i]>0?i:maxx),s+=a[i];
for(int i=0;i<n;i++)
scanf("%lld",&b[i]),maxx1=(b[i]>0?i:maxx1),s1+=b[i];
if(s<s1) a[0]+=s1-s;
else b[0]+=s-s1;
if(maxx+maxx1<n)
{
printf("0\n");
continue;
}
int r=n-1,flag=1;ll ans=0;
for(int i=0;i<n&&r>=0;)
{
while(r>=0&&b[r]==0) r--;
if(i+r>=n-1&&a[i]>0)
{
if(i+r>=n) flag=0;
ll tmp=min(a[i],b[r]);
a[i]-=tmp,b[r]-=tmp;
ans+=tmp;
}
else i++;
}
printf("%lld\n",ans-flag);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5888kb
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: 58ms
memory: 5880kb
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:
1 0 4 0 3 3 3 2 0 0 1 0 2 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 1 0 0 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 1 1 2 0 3 4 0 2 5 0 1 1 0 0 0 2 1 3 0 1 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 1 0 1 0 1 0 0 2 4 1 2 3 2 2 2 0 1 0 0 2 3 1 3 0 0 2 2 3 0 1 2 0 1 1 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'