QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#656629 | #8057. Best Carry Player 4 | eastcloud | WA | 9ms | 3628kb | C++20 | 1.4kb | 2024-10-19 13:27:19 | 2024-10-19 13:27:20 |
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;
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;
for(ll i=0;i<m;i++){
while(pos!=-1 && a[i] && pos+i>=m-1){
ll d=min(a[i],b[pos]);
b[pos]-=d;a[i]-=d;flag|=(pos+i>=m);
res+=d;
if(!b[pos])pos--;
}
}
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";
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
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: 9ms
memory: 3492kb
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 4 3 2 0 0 1 1 3 0 3 1 1 0 0 0 1 0 4 1 4 2 0 2 3 3 1 5 0 0 2 0 1 1 1 0 1 3 5 3 2 2 1 0 0 2 3 2 0 3 1 2 1 1 1 1 0 4 2 2 2 2 0 3 3 0 2 0 2 0 1 2 1 2 0 3 4 0 2 5 0 2 1 1 1 0 3 2 4 0 2 0 4 3 3 0 2 2 1 1 3 1 1 0 1 0 1 0 3 2 2 0 2 1 1 0 1 0 1 3 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 1 0 2 2 3 0 2 2 1 2 1 ...
result:
wrong answer 6th numbers differ - expected: '3', found: '4'