CF1738B.Prefix Sum Addicts

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Suppose a1,a2,,ana_1, a_2, \dots, a_n is a sorted integer sequence of length nn such that a1a2ana_1 \leq a_2 \leq \dots \leq a_n .

For every 1in1 \leq i \leq n , the prefix sum sis_i of the first ii terms a1,a2,,aia_1, a_2, \dots, a_i is defined by $$$$ s_i = \sum_{k=1}^i a_k = a_1 + a_2 + \dots + a_i. $$

Now you are given the last kk terms of the prefix sums, which are s_nk+1,dots,s_n1,s_ns\_{n-k+1}, \\dots, s\_{n-1}, s\_{n} . Your task is to determine whether this is possible.

Formally, given kk integers s_nk+1,dots,s_n1,s_ns\_{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_na\_1, a\_2, \\dots, a\_n such that

  1. a_1leqa_2leqdotsleqa_na\_1 \\leq a\_2 \\leq \\dots \\leq a\_n , and
  2. s_i=a_1+a_2+dots+a_is\_i = a\_1 + a\_2 + \\dots + a\_i for all nk+1leqileqnn-k+1 \\leq i \\leq n$$.

输入格式

Each test contains multiple test cases. The first line contains an integer tt ( 1t1051 \leq t \leq 10^5 ) — 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 nn ( 1n1051 \leq n \leq 10^5 ) and kk ( 1kn1 \leq k \leq n ), indicating the length of the sequence aa and the number of terms of prefix sums, respectively.

The second line of each test case contains kk integers snk+1,,sn1,sns_{n-k+1}, \dots, s_{n-1}, s_{n} ( 109si109-10^9 \leq s_i \leq 10^9 for every nk+1inn-k+1 \leq i \leq n ).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5 .

输出格式

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]a = [1, 1, 1, 1, 1] .

In the second test case, we can choose, for example, a=[3,2,1,0,1,2,3]a = [-3, -2, -1, 0, 1, 2, 3] .

In the third test case, the prefix sums define the only sequence a=[2,1,1]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.

首页