A13772 | Reorder
时间限制1s
内存限制256MB
通过 / 提交0/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 $\sum_{i=1}^{n}{\sum_{j=i}^{n}{\frac{a_j}{j}}}$ equals $m$ ? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for example, $\frac{5}{2}=2.5$ .
输入格式
The first line contains a single integer $t$ — the number of test cases ( $1 \le t \le 100$ ). The test cases follow, each in two lines.
The first line of a test case contains two integers $n$ and $m$ ( $1 \le n \le 100$ , $0 \le m \le 10^6$ ). The second line contains integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 10^6$ ) — the elements of the array.
The first line of a test case contains two integers $n$ and $m$ ( $1 \le n \le 100$ , $0 \le m \le 10^6$ ). The second line contains integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 10^6$ ) — the elements of the array.
输出格式
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.
输入输出样例
输入 #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]$ . The sum is equal to $(\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 $\sum_{j=i}^{n}{\frac{a_j}{j}}$ , while the summation of brackets corresponds to the sum over $i$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted