CF1738B.Prefix Sum Addicts

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

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

For every 1≤i≤n1 \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 sn−k+1,…,sn−1,sns_{n-k+1}, \dots, s_{n-1}, s_{n}. Your task is to determine whether this is possible.

Formally, given kk integers sn−k+1,…,sn−1,sns_{n-k+1}, \dots, s_{n-1}, s_{n}, the task is to check whether there is a sequence a1,a2,…,ana_1, a_2, \dots, a_n such that

  1. a1≤a2≤⋯≤ana_1 \leq a_2 \leq \dots \leq a_n, and
  2. si=a1+a2+⋯+ais_i = a_1 + a_2 + \dots + a_i for all n−k+1≤i≤nn-k+1 \leq i \leq n.

假设 a1,a2,…,ana_1, a_2, \dots, a_n 是一个长度为 nn 的已排序整数序列,满足 a1≤a2≤⋯≤ana_1 \leq a_2 \leq \dots \leq a_n。

对每个 1≤i≤n1 \leq i \leq n,前 ii 项 a1,a2,…,aia_1, a_2, \dots, a_i 的前缀和 sis_i 定义为

s_i=sum_k=1ia_k=a_1+a_2+dots+a_i.s\_i = \\sum\_{k=1}^i a\_k = a\_1 + a\_2 + \\dots + a\_i.

现在你被给定前缀和的最后 kk 项,即 sn−k+1,…,sn−1,sns_{n-k+1}, \dots, s_{n-1}, s_{n}。你的任务是判断这种情况是否可能。

形式化地说,给定 kk 个整数 sn−k+1,…,sn−1,sns_{n-k+1}, \dots, s_{n-1}, s_{n},任务是判断是否存在一个序列 a1,a2,…,ana_1, a_2, \dots, a_n,使得

  1. a1≤a2≤⋯≤ana_1 \leq a_2 \leq \dots \leq a_n,且
  2. 对所有 n−k+1≤i≤nn-k+1 \leq i \leq n,均有 si=a1+a2+⋯+ais_i = a_1 + a_2 + \dots + a_i。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1051 \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 (1≤n≤1051 \leq n \leq 10^5) and kk (1≤k≤n1 \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 sn−k+1,…,sn−1,sns_{n-k+1}, \dots, s_{n-1}, s_{n} (−109≤si≤109-10^9 \leq s_i \leq 10^9 for every n−k+1≤i≤nn-k+1 \leq i \leq n).

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5),表示测试用例的数量。接下来的各行描述各个测试用例。

每个测试用例的第一行包含两个整数 nn(1≤n≤1051 \leq n \leq 10^5)和 kk(1≤k≤n1 \leq k \leq n),分别表示序列 aa 的长度以及前缀和项数。

每个测试用例的第二行包含 kk 个整数 sn−k+1,…,sn−1,sns_{n-k+1}, \dots, s_{n-1}, s_{n}(对所有满足 n−k+1≤i≤nn-k+1 \leq i \leq n 的 ii,有 −109≤si≤109-10^9 \leq s_i \leq 10^9)。

保证所有测试用例中 nn 的总和不超过 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).

对于每个测试用例,如果可能则输出 “YES”(不带引号),否则输出 “NO”(不带引号)。

您可以以任意大小写形式输出 “YES” 和 “NO”(例如,字符串 “yEs”、“yes” 和 “Yes” 均会被识别为肯定回答)。

输入输出样例

  • 输入#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.

在第一个测试用例中,我们仅有唯一序列 a=[1,1,1,1,1]a = [1, 1, 1, 1, 1]。

在第二个测试用例中,我们可以选择,例如,a=[−3,−2,−1,0,1,2,3]a = [-3, -2, -1, 0, 1, 2, 3]。

在第三个测试用例中,前缀和确定了唯一序列 a=[2,1,1]a = [2, 1, 1],但该序列并非有序。

在第四个测试用例中,可以证明不存在满足给定前缀和的序列。

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

首页