Codeforces Round #678 (Div. 2)------Reorder

题目

For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that在这里插入图片描述
It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for example, 5 / 2=2.5.

Input
The first line contains a single integer t — the number of test cases (1≤t≤100). The test cases follow, each in two lines.

The first line of a test case contains two integers n and m (1≤n≤100, 0≤m≤106). The second line contains integers a1,a2,…,an (0≤ai≤106) — the elements of the array.

Output
For each test case print “YES”, if it is possible to reorder the elements of the array in such a way that the given formula gives the given value, and “NO” otherwise.

样例

//输入:
2
3 8
2 5 1
4 4
0 1 2 3
//输出:
YES
NO

题意

给定一个含有n个元素的数值a,判断是否满足题目中的那个公式,若满足,输出YES,否则输出NO;

题解

公式前几项展开便可发现规律,最后是 在这里插入图片描述
因此,题目简化后就是求数组元素的和是否等于m。

AC代码

#include<iostream>
using namespace std;
int main()
{
	int n, m, t;
	cin >> t;
	while (t--) {
		int sum = 0;
		cin >> n >> m;

		for (int i = 0; i < n; i++) {
			int x; cin >> x;
			sum += x;
		}
		if (sum == m)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值