QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719785 | #8057. Best Carry Player 4 | qzez# | WA | 1ms | 6024kb | C++14 | 930b | 2024-11-07 08:54:58 | 2024-11-07 08:54:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=5e5+5;
int m;ll A[N],B[N];
void Solve(){
scanf("%d",&m);
for(int i=0;i<m;i++) scanf("%lld",&A[i]);
for(int i=0;i<m;i++) scanf("%lld",&B[i]);
int m1=0;for(int i=0;i<m;i++) if(A[i]) m1=i;
int m2=0;for(int i=0;i<m;i++) if(B[i]) m2=i;
ll s1=accumulate(A,A+m,0ll),s2=accumulate(B,B+m,0ll);
if(s1<s2) A[0]+=s2-s1;
else B[0]+=s1-s2;
if(m1+m2<m){puts("0");return;}
ll sum=0,ans=0;int flag=0,glag=0;
for(int i=0;i<m;i++){
ll w=min(1ll*A[i],sum);
if(w){
sum-=w;A[i]-=w;
flag=1;
ans+=w;
}
w=min(A[i],B[m-i-1]);
A[i]-=w;B[m-i-1]-=w;ans+=w;
if(w) glag=1;
if(A[i]&&glag) flag=1;
sum+=B[m-i-1];
// cerr<<i<<' '<<A[i]<<' '<<sum<<'\n';
}
printf("%lld\n",max(ans-(!flag),0ll));
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6024kb
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:
6 1 2 467900 29
result:
wrong answer 1st numbers differ - expected: '5', found: '6'