QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#657087 | #8057. Best Carry Player 4 | ucup-team4992# | WA | 44ms | 7784kb | C++20 | 1.6kb | 2024-10-19 14:11:19 | 2024-10-19 14:11:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int M=2e5+5;
ll A[M],B[M],C[M],D[M];
int m;
void solve(){
cin>>m;
for(int i=0; i<m; i++) cin>>A[i],C[i]=A[i];
for(int i=0; i<m; i++) cin>>B[i],D[i]=B[i];
ll ans=0;
for(int i=0; i<m; i++){
ll a=A[i],b=B[m-1-i];
if(i==0) a=2e9;
if(i==m-1) b=2e9;
// cout<<"i = "<<i<<" , a = "<<a<<" , m-1-i = "<<m-1-i<<" , b = "<<b<<"\n";
ll res=min(a,b);
A[i]-=res; B[m-1-i]-=res;
ans+=res;
}
bool flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(B[m-i]>0);
if(flag && A[i]>0){
can=1;
break;
}
}
if(can){
ll tot=0;
for(int i=0; i<m; i++){
tot+=B[m-i];
ll res=min(tot,A[i]);
tot-=res;
ans+=res;
}
cout<<ans<<"\n";
}else{
flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(B[m-i]>0);
if(flag && C[i]>0){
can=1;
break;
}
}
if(can){
cout<<ans<<"\n";
return;
}
flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(A[m-i]>0);
if(flag && D[i]>0){
can=1;
break;
}
}
if(can){
cout<<ans<<"\n";
return;
}
cout<<ans-1<<"\n";
}
return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7784kb
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: 44ms
memory: 7692kb
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 -1 4 -1 3 3 3 2 -1 -1 1 1 3 0 3 0 0 -1 -1 0 0 0 2 0 4 1 -1 2 4 3 1 5 0 -1 2 0 0 1 1 -1 0 2 5 3 2 2 2 -1 1 2 2 2 -1 4 0 2 1 1 0 1 -1 4 1 1 2 2 -1 3 2 -1 2 -1 1 -1 0 1 1 2 0 3 4 -1 2 5 -1 2 1 0 0 -1 3 2 3 -1 2 0 4 3 3 0 2 2 1 1 3 1 1 -1 0 -1 1 -1 3 2 1 -1 2 1 1 0 1 -1 0 2 3 1 3 3 2 2 1 -1 2 -1 0 2 3...
result:
wrong answer 2nd numbers differ - expected: '0', found: '-1'