QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719772 | #8057. Best Carry Player 4 | qzez# | WA | 58ms | 6040kb | C++14 | 880b | 2024-11-07 08:48:44 | 2024-11-07 08:48:45 |
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;
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;
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: 100
Accepted
time: 1ms
memory: 6040kb
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: 5988kb
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'