QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741287 | #8057. Best Carry Player 4 | quark404# | RE | 0ms | 7632kb | C++20 | 1.9kb | 2024-11-13 14:02:00 | 2024-11-13 14:02:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(a, b, c) for (int a = b; a <= c; ++a)
int n;
int a[500005];
int b[500005];
void init()
{
cin>>n;
int ca=0,cb=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
ca+=a[i];
}
for(int i=0;i<n;i++)
{
cin>>b[i];
cb+=b[i];
}
if(ca<cb)
{
for(int i=0;i<n;i++) swap(a[i],b[i]);
}
//pre 0 in b,ca>cb
return;
}
bool hava[500005],havb[500005];
void solve()
{
for(int i=0;i<=n;i++) hava[i]=havb[i]=false;
int cnt_n1=0;
bool hav_mplus=false;
if(a[n-1]>0)
{
cnt_n1=a[n-1];
havb[0]=true;
}
int now=1;
for(int i=n-2;i>=0;i--)
{
now=max(now,(n-1)-i);
while(a[i]>0&&now<=n-1)
{
if(b[now]==0)
{
now++;
continue;
}
if(i+now>=n) hav_mplus=true;
int v=min(a[i],b[now]);
cnt_n1+=v;
a[i]-=v;
b[now]-=v;
havb[now]=true;
}
}
assert(b[n-1]==0);
if(hav_mplus==true)
{
cout<<cnt_n1<<'\n';
return;
}
int r=-1;
for(int i=n-1;i>=0;i--)
{
if(b[i]>0)
{
r=i;
break;
}
}
for(int i=r-1;i>=0;i--)
{
if(havb[i]==true)
{
cout<<cnt_n1<<'\n';
return;
}
}
int hav_diff=0;
for(int i=0;i<=n-1;i++)
{
if(havb[i]==true) hav_diff++;
}
if(hav_diff>=2) cout<<cnt_n1-1<<'\n';
else cout<<0<<'\n';
return;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
{
init();
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7632kb
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
Runtime Error
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...