QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630240 | #8057. Best Carry Player 4 | Rilllo# | WA | 41ms | 7808kb | C++23 | 2.1kb | 2024-10-11 17:17:10 | 2024-10-11 17:17:11 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define Pa pair<int,int>
using namespace std;
const int N=2e6+10,mod=1e9+7;
int a[N],b[N],c[N],d[N];
int m;
//bool check(int x){
// for(int i=0;i<m;i++){
// a[i]=c[i],b[i]=d[i];
// }
// int now=0,res=0,yu=x;
// for(int i=m-1;i>=0;i--){
// int cnt1=a[i];
// while(now+i<m-1)now++;
// int mn=min({yu,b[now],a[i]});
// a[i]-=mn;
// res+=mn;
// yu-=mn;
// if(a[i]){
//
// }
// }
//
// for()
//}
void solve(){cin>>m;
int mx=0;
bool flag= false;
for(int i=0;i<=m-1;i++){
cin>>a[i];
if(a[i]){
mx=max(mx,i);
}
}
for(int i=0;i<=m-1;i++){
cin>>b[i];
if(b[i]){
if(i+mx>=m)flag= true;
}
}
if(!flag){
cout<<0<<'\n';
return;
}
int mn=1e10;
int ans=0;
int l=1;
bool f= false;
for(int i=m-2;i>=1;i--){
while(a[i]&&l<m-1){
while(l+i<m-1)l++;
if(l>=m-1)break;
int minn=min(a[i],b[l]);
if(i+l>=m)f= true;
a[i]-=minn;
ans+=minn;
b[l]-=minn;
if(!b[l])l++;
}
if(l>=m-1)break;
}
int s1=0,s2=0;
// for(int i=0;i<=m-1;i++)cout<<a[i]<<' ';
// cout<<'\n';
// for(int i=0;i<=m-1;i++)cout<<b[i]<<' ';
// cout<<'\n';
for(int i=0;i<m-1;i++){
s1+=a[i];
if(a[i]&&i>0&&b[m-1]){
f= true;
}
}
for(int i=0;i<m-1;i++){
s2+=b[i];
if(b[i]&&i>0&&a[m-1]){
f= true;
}
}
int mn1=min(s1,b[m-1]);
int mn2=min(s2,a[m-1]);
ans+=mn1+mn2;
a[m-1]-=mn2;
b[m-1]-=mn1;
ans+=max(a[m-1],b[m-1]);
// cout<<f<<' ';
// cout<<ans<<' ';
if(!f)ans--;
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T=1;cin>>T;
while(T--)solve();
}
//1
//10
//5 3 5 3 2 4 2 4 1 5
//9 9 8 2 4 4 3 5 3 0
//5 1 0 0 0 0 0 0 0 5
//9 8 4 0 0 2 0 1 0 0
//23
//28
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7748kb
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: 41ms
memory: 7808kb
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 3 3 3 1 0 0 1 1 3 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 2 0 1 2 2 2 0 3 0 2 0 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 2 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 0 0 3 2 2 0 2 1 1 0 2 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 0 ...
result:
wrong answer 8th numbers differ - expected: '2', found: '1'