B. Array Decrements Codeforces Round #797 (Div. 3)

本文介绍了一个数组操作问题的解决思路,通过比较两个数组a和b,判断是否可以通过一系列操作使得a与b相等。主要讨论了如何计算需要进行的操作次数,并验证最终状态的一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 题意:给你一个数组a和b,a可以进行一个操作:

a数组中的所有数都--(如果小于0就为0 )

问可不可以通过任意次操作,使a和b相等。

思路:直接需要删除的最大的次数就可以了,然后全删一边,小于0的变成0,然后看相不相等就好。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll a[N],b[N];



int main()
{
	int t;
	sc_int(t);
	while(t--)
	{
		int n;
		sc_int(n);
		for(int i =1;i<=n;i++)
		cin>>a[i];
		for(int i =1;i<=n;i++)
		cin>>b[i];		
		ll sum_0=0,sum=0;
		bool flag=0;
		for(int i =1;i<=n;i++)
		{
			if(b[i]==0)
			sum_0=max(a[i],sum_0);
			else if(sum==0||sum==a[i]-b[i])
			sum=a[i]-b[i];
			else flag=1;
		}
		if(flag||sum<0||(sum_0>sum&&sum!=0))cout<<"NO\n";
		else cout<<"YES\n";
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值