CF1738B.Prefix Sum Addicts
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Suppose a1,a2,…,an is a sorted integer sequence of length n such that a1≤a2≤⋯≤an .
For every 1≤i≤n , the prefix sum si of the first i terms a1,a2,…,ai is defined by $$$$ s_i = \sum_{k=1}^i a_k = a_1 + a_2 + \dots + a_i. $$
Now you are given the last k terms of the prefix sums, which are s_n−k+1,dots,s_n−1,s_n . Your task is to determine whether this is possible.
Formally, given k integers s_n−k+1,dots,s_n−1,s_n , the task is to check whether there is a sequence a_1,a_2,dots,a_n such that
- a_1leqa_2leqdotsleqa_n , and
- s_i=a_1+a_2+dots+a_i for all n−k+1leqileqn$$.
输入格式
Each test contains multiple test cases. The first line contains an integer t ( 1≤t≤105 ) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains two integers n ( 1≤n≤105 ) and k ( 1≤k≤n ), indicating the length of the sequence a and the number of terms of prefix sums, respectively.
The second line of each test case contains k integers sn−k+1,…,sn−1,sn ( −109≤si≤109 for every n−k+1≤i≤n ).
It is guaranteed that the sum of n over all test cases does not exceed 105 .
输出格式
For each test case, output "YES" (without quotes) if it is possible and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
输入输出样例
输入#1
4 5 5 1 2 3 4 5 7 4 -6 -5 -3 0 3 3 2 3 4 3 2 3 4
输出#1
Yes Yes No No
说明/提示
In the first test case, we have the only sequence a=[1,1,1,1,1] .
In the second test case, we can choose, for example, a=[−3,−2,−1,0,1,2,3] .
In the third test case, the prefix sums define the only sequence a=[2,1,1] , but it is not sorted.
In the fourth test case, it can be shown that there is no sequence with the given prefix sums.