QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667299 | #8057. Best Carry Player 4 | eastcloud | WA | 14ms | 5544kb | C++14 | 1.6kb | 2024-10-22 22:05:45 | 2024-10-22 22:05:47 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define IL inline
#define mod 998244353
#define N 200005
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
void write(ll x){
if(x<0)x=-x,putchar('-');
if(x/10)write(x/10);
putchar(x%10+'0');
}
ll a[N],b[N];
void solve(){
ll m=read(),suma=0,sumb=0;a[m]=b[m]=0;
for(ll i=0;i<m;i++)a[i]=read(),suma+=a[i];
for(ll i=0;i<m;i++)b[i]=read(),sumb+=b[i];
ll pos=m-1,res=0,flag=0;
if(suma<sumb)a[0]+=sumb-suma;
else b[0]+=suma-sumb;
ll lasA=0,lasB=0;
for(ll i=0;i<m;i++)lasA=(a[i]?i:lasA),lasB=(b[i]?i:lasB);
for(ll i=0;i<m;i++){
while(pos!=-1 && a[i] && pos+i>=m-1){
if(!b[pos]){pos--;continue;}
ll d=min(a[i],b[pos]);
b[pos]-=d;a[i]-=d;flag|=(pos+i>=m);
res+=d;
if(!b[pos])pos--;
}
}
for(int i=0;i<=lasA;i++)if(b[m-i])flag=1;
for(int i=0;i<=lasB;i++)if(a[m-i])flag=1;
if(res && !flag)res--;
write(res);putchar('\n');
}
int main(){
#ifdef EAST_CLOUD
freopen("a.in","r",stdin);
#endif
ll T=read();while(T--)solve();
}
//cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
//cerr<<"\n"<<clock()*1.0/CLOCKS_PER_SEC*1000<<"ms\n";
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5500kb
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: 14ms
memory: 5544kb
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 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 1 1 0 1 0 4 1 1 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 1 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 1 1 1 ...
result:
wrong answer 63rd numbers differ - expected: '0', found: '1'