QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#937872 | #8057. Best Carry Player 4 | Yurily# | WA | 52ms | 9960kb | C++20 | 1.9kb | 2025-03-16 17:09:30 | 2025-03-16 17:09:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAX=5e5+5;
int m;
int a[MAX],b[MAX];
int a1[MAX],b1[MAX];
void sol(){
cin>>m;
for(int i=0;i<m;++i){
cin>>a[i];
}
for(int i=0;i<m;++i){
cin>>b[i];
}
long long ans=0;
for(int i=1;i<m-1;++i)
ans+=min(a[i],b[m-1-i]);
ans+=a[m-1]+b[m-1];
for(int i=1;i<m-1;++i)
a1[i]=a[i]-min(a[i],b[m-1-i]);
for(int i=1;i<m-1;++i)
b1[i]=b[i]-min(b[i],a[m-1-i]);
a1[m-1]=b1[m-1]=0;
long long tot=0,sum=0;
for(int i=1;i<m-1;++i){
sum+=b1[m-i];
int cur=min((long long)a1[i],sum);
tot+=cur;
sum-=cur;
}
if(tot){
ans+=tot;
cout<<ans<<"\n";
}
else{
int pa=0;
for(int i=m-1;i>=1;--i){
if(a1[i]){
pa=i;
break;
}
}
for(int i=m-1;i>=0;--i){
if(b[i]||!i){
if(i+pa>=m){
cout<<ans<<"\n";
return;
}
}
}
int pb=0;
for(int i=m-1;i>=1;--i){
if(b1[i]){
pb=i;
break;
}
}
if(pb!=-1)
for(int i=m-1;i>=0;--i){
if(a[i]||!i){
if(i+pb>=m){
cout<<ans<<"\n";
return;
}
}
}
pa=m-1,pb=m-1;
while(pa>=1&&!a[pa])
pa--;
while(pb>=1&&!b[pb])
pb--;
if(pa+pb>=m){
cout<<ans-1<<"\n";
}
else
cout<<0<<"\n";
}
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--)
sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9960kb
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: 52ms
memory: 9832kb
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 4 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 4 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 2 2 2 0 4 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 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 1 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 5th numbers differ - expected: '3', found: '4'