QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630144 | #8057. Best Carry Player 4 | Rilllo# | WA | 42ms | 7684kb | C++23 | 2.0kb | 2024-10-11 16:42:49 | 2024-10-11 16:43:00 |
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 pos1=-1,pos2=-1;
int l=0;
for(int i=m-1;i>=0;i--){
if(a[i]){
while(i+l<m)l++;
while(l<m&&!b[l])l++;
if(l<m){
if(l+i<mn){
mn=l+i;
pos1=i;
pos2=l;
}
}
}
}
int ans=1;
a[pos1]--,b[pos2]--;
l=1;
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]);
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++){
s1+=a[i];
}
for(int i=0;i<m-1;i++){
s2+=a[i];
}
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<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T=1;cin>>T;
while(T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7680kb
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: 42ms
memory: 7684kb
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 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 3 3 1 4 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 2 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 2 1 1 0 0 0 1 0 3 2 2 0 2 1 1 0 1 0 0 2 3 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 32nd numbers differ - expected: '5', found: '4'