QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#536394 | #8057. Best Carry Player 4 | ucup-team3591# | WA | 11ms | 3352kb | C++14 | 1.8kb | 2024-08-29 10:22:52 | 2024-08-29 10:22:52 |
Judging History
answer
#include<cstdio>
typedef long long ll;
inline ll read(){
ll x=0;
int f=0,ch=0;
while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
return f?-x:x;
}
inline void write(ll x,char end='\n'){
if(x==0){
putchar('0');
putchar(end);
return;
}
if(x<0) putchar('-'),x=-x;
int ch[40]={0},cnt=0;
while(x){
ch[cnt++]=(int)(x%10);
x/=10;
}
while(cnt--) putchar(ch[cnt]+48);
putchar(end);
}
inline ll max(ll x,ll y){return x>y?x:y;}
inline ll min(ll x,ll y){return x<y?x:y;}
const ll inf=1e15;
const int N=5e5+5;
ll a[N],b[N],m;
inline void solve(){
m=read();
ll sa=0,sb=0;
for(int i=0;i<m;++i) a[i]=read(),sa+=a[i];
for(int i=0;i<m;++i) b[i]=read(),sb+=b[i];
a[0]+=sb-sa,b[0]+=sa-sb;
ll t=min(a[0],b[0]);
a[0]-=t,b[0]-=t;
int flag=0;
ll now=0,can=0;
for(int i=1;i<m;++i){
now+=b[m-i];
if(now&&a[i]){
flag=1;
ll t=min(now,a[i]);
now-=t;
can+=t;
}
}
if(!flag){
puts("0");
return;
}
flag=0;
ll ans=0;
int l=m-1;
int mna=-1,mnb=-1;
for(int i=0;i<m;++i){
while(a[i]&&l>=m-i-1){
if(!b[l]){
--l;
continue;
}
int t=min(a[i],b[l]);
if(mna==-1) mna=i;
mnb=l;
if(i+l>=m) flag=1;
ans+=t;
a[i]-=t;
b[l]-=t;
if(!b[l]) --l;
}
}
ans+=a[m-1]+b[m-1];
if(!flag){
int taga=-1,tagb=-1;
for(int i=mna+1;i<m;++i){
if(a[i]){
taga=i;
break;
}
}
for(int i=mnb+1;i<m;++i){
if(b[i]){
tagb=i;
break;
}
}
if(taga==-1&&tagb==-1) ans--;
else if(taga==-1){
if(tagb==m-1) ans--;
}
else if(tagb==-1){
if(taga==m-1) ans--;
}
else{
if(taga==m-1&&tagb==m-1) ans--;
}
}
write(ans,'\n');
}
int main(){
int T=read();
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3352kb
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: 11ms
memory: 3320kb
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 4 3 2 2 2 0 1 2 2 2 0 3 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 2 2 2 2 0 2 0 0 2 3 1 3 1 0 2 2 2 0 1 2 0 1 1 ...
result:
wrong answer 43rd numbers differ - expected: '5', found: '4'