QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#656655#8057. Best Carry Player 4eastcloudWA 9ms5560kbC++201.4kb2024-10-19 13:30:002024-10-19 13:30:00

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 13:30:00]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:5560kb
  • [2024-10-19 13:30:00]
  • 提交

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){
			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--;
		}
	}
	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: 5560kb

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: 3696kb

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:

1
0
4
0
3
3
3
2
0
0
1
0
2
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
1
0
0
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
1
1
0
0
0
2
1
3
0
1
0
4
3
3
0
2
2
1
1
3
1
1
0
0
0
1
0
3
2
2
0
1
0
1
0
1
0
0
2
4
1
2
3
2
2
2
0
1
0
0
2
3
1
3
0
0
2
2
3
0
1
2
1
1
1
...

result:

wrong answer 1st numbers differ - expected: '2', found: '1'