20201210大一集训题x题之思维题sum

24 篇文章 0 订阅
24 篇文章 0 订阅

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 ∑ni=1∑nj=iajj equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for example, 52=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.

Example
Input
2
3 8
2 5 1
4 4
0 1 2 3
Output
YES
NO
Note
In the first test case one of the reorders could be [1,2,5]. The sum is equal to (11+22+53)+(22+53)+(53)=8. The brackets denote the inner sum ∑nj=iajj, while the summation of brackets corresponds to the sum over i.

思维:
题目都是障眼法;主要是他多加的值都是分层n份,又加了n份;
所以都没变!

代码:

#include<cstdio>
#include<math.h>
#include<string.h>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int a[10005];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		int n,m,sum=0;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			sum+=a[i];
		} 
		if(m==sum) printf("YES\n");
		else printf("NO\n"); 
	} 
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值