CF1436A.Reorder

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For a given array aa consisting of nn integers and a given integer mm find if it is possible to reorder elements of the array aa in such a way that ∑i=1n∑j=inajj\sum_{i=1}^{n}{\sum_{j=i}^{n}{\frac{a_j}{j}}} equals mm? 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\frac{5}{2}=2.5.

给定一个由 nn 个整数组成的数组 aa 和一个整数 mm,请判断是否可以对数组 aa 的元素进行重排(不允许删除或插入任何元素),使得 ∑i=1n∑j=inajj\sum_{i=1}^{n}{\sum_{j=i}^{n}{\frac{a_j}{j}}} 的值恰好等于 mm?注意:除法运算不进行任何舍入,例如 52=2.5\frac{5}{2}=2.5。

输入格式

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

The first line of a test case contains two integers nn and mm (1≤n≤1001 \le n \le 100, 0≤m≤1060 \le m \le 10^6). The second line contains integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1060 \le a_i \le 10^6) — the elements of the array.

第一行包含一个整数 tt —— 测试用例的数量(1≤t≤1001 \le t \le 100)。随后是 tt 个测试用例,每个测试用例占两行。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤1001 \le n \le 100,0≤m≤1060 \le m \le 10^6)。第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1060 \le a_i \le 10^6)—— 数组的元素。

输出格式

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.

对于每个测试用例,如果可以重新排列数组的元素,使得给定公式计算出给定的值,则输出 “YES”;否则输出 “NO”。

输入输出样例

  • 输入#1

    2
    3 8
    2 5 1
    4 4
    0 1 2 3

    输出#1

    YES
    NO

说明/提示

In the first test case one of the reorders could be [1,2,5][1, 2, 5]. The sum is equal to (11+22+53)+(22+53)+(53)=8(\frac{1}{1} + \frac{2}{2} + \frac{5}{3}) + (\frac{2}{2} + \frac{5}{3}) + (\frac{5}{3}) = 8. The brackets denote the inner sum ∑j=inajj\sum_{j=i}^{n}{\frac{a_j}{j}}, while the summation of brackets corresponds to the sum over ii.

在第一个测试用例中,一种可能的重排是 [1,2,5][1, 2, 5]。其总和为 (11+22+53)+(22+53)+(53)=8(\frac{1}{1} + \frac{2}{2} + \frac{5}{3}) + (\frac{2}{2} + \frac{5}{3}) + (\frac{5}{3}) = 8。括号表示内层求和 ∑j=inajj\sum_{j=i}^{n}{\frac{a_j}{j}},而括号的累加则对应于对 ii 的求和。

输入解题思路,AI测评打分。不知道怎么写?

首页