CF2248E.Excuse for Breaks

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given three integers nn, mm, and dd, and two arrays p1,p2,…,pmp_1, p_2, \ldots, p_m and r1,r2,…,rmr_1, r_2, \ldots, r_m. The array pp is strictly increasing.

For a binary array aa of any positive finite length (so ∣a∣|a| need not equal nn), define its value f(a)f(a) using the following pseudocode:

function f(a):    v := 0    c := 0    for i from 1 to length(a):        if a[i] is equal to 1:            v := v + d            c := c + 1        else:            c := 0        for j from 1 to m:            if c is equal to p[j]:                v := v + r[j]        if c is equal to n:            c := 0    return vHere, ":=" denotes the assignment operation.

Let I(a)I(a) denote the array [1,1,…,1][1,1,\ldots,1] of length ∣a∣|a|. In other words, I(a)I(a) consists of ∣a∣|a| ones.

Determine whether there exists a binary (consisting only of zeros and ones) array aa such that f(a)>f(I(a))f(a) \gt f(I(a)).

给你三个整数 nn、mm 和 dd,以及两个数组 p1,p2,…,pmp_1, p_2, \ldots, p_m 和 r1,r2,…,rmr_1, r_2, \ldots, r_m。数组 pp 是严格递增的。

对于任意正有限长度的二进制数组 aa(即 ∣a∣|a| 不必等于 nn),其值 f(a)f(a) 由以下伪代码定义:

function f(a):    v := 0    c := 0    for i from 1 to length(a):        if a[i] is equal to 1:            v := v + d            c := c + 1        else:            c := 0        for j from 1 to m:            if c is equal to p[j]:                v := v + r[j]        if c is equal to n:            c := 0    return v

其中,“:=” 表示赋值操作。

记 I(a)I(a) 为长度为 ∣a∣|a| 的全 11 数组 [1,1,…,1][1,1,\ldots,1]。换言之,I(a)I(a) 由 ∣a∣|a| 个 11 组成。

判断是否存在一个二进制(仅含 00 和 11)数组 aa,使得 f(a)>f(I(a))f(a) \gt f(I(a))。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤20001 \le t \le 2000). The description of the test cases follows.

The first line of each test case contains three integers nn, mm, and dd (1≤n≤1091 \le n \le 10^9, 0≤m≤20000 \le m \le 2000, 0≤d≤1090 \le d \le 10^9).

The ii-th of the next mm lines contains two integers pip_i and rir_i (1≤pi≤n1 \le p_i \le n, 1≤ri≤1091 \le r_i \le 10^9).

The array pp is strictly increasing.

It is guaranteed that the sum of mm over all test cases does not exceed 20002000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤20001 \le t \le 2000)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 dd(1≤n≤1091 \le n \le 10^9,0≤m≤20000 \le m \le 2000,0≤d≤1090 \le d \le 10^9)。

接下来的 mm 行中,第 ii 行包含两个整数 pip_i 和 rir_i(1≤pi≤n1 \le p_i \le n,1≤ri≤1091 \le r_i \le 10^9)。

数组 pp 严格递增。

保证所有测试用例中 mm 的总和不超过 20002000。

输出格式

For each test case, output "YES" if such a binary array aa exists, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

对于每个测试用例,如果存在满足条件的二进制数组 aa,则输出 "YES";否则输出 "NO"。

你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均将被识别为肯定回答。

输入输出样例

  • 输入#1

    3
    6 4 3
    2 5
    3 9
    4 1
    5 3
    7 3 5
    2 5
    4 5
    7 10
    684492057 3 386217943
    367971233 991739271
    612599954 429216213
    684492056 402931836

    输出#1

    YES
    NO
    YES

说明/提示

In the first test case, you can choose a=[1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1]a = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1].

The array aa contains 1616 ones, so the total contribution of dd is 16⋅3=4816 \cdot 3 = 48. Its runs of consecutive ones have lengths 99, 44, and 33. The corresponding total rewards are 3232, 1515, and 1414, respectively. Therefore, f(a)=48+32+15+14=109f(a) = 48 + 32 + 15 + 14 = 109.

Moreover, I(a)I(a) consists of 1818 ones. During the computation of f(I(a))f(I(a)), they form three complete blocks of 66 ones, and each block contributes 6⋅3+5+9+1+3=366 \cdot 3 + 5 + 9 + 1 + 3 = 36. Thus, f(I(a))=3⋅36=108f(I(a)) = 3 \cdot 36 = 108. Since f(a)>f(I(a))f(a) \gt f(I(a)), the answer is "YES".

In the second test case, no binary array aa satisfies f(a)>f(I(a))f(a) \gt f(I(a)), so the answer is "NO".

在第一个测试用例中,你可以选择 a=[1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1]a = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1]。

数组 aa 包含 1616 个 11,因此 dd 的总贡献为 16⋅3=4816 \cdot 3 = 48。其连续的 11 段(即“游程”)长度分别为 99、44 和 33。对应获得的总奖励分别为 3232、1515 和 1414。因此,f(a)=48+32+15+14=109f(a) = 48 + 32 + 15 + 14 = 109。

此外,I(a)I(a) 由 1818 个 11 组成。在计算 f(I(a))f(I(a)) 时,它们构成三个完整的、每块含 66 个 11 的块,且每块的贡献为 6⋅3+5+9+1+3=366 \cdot 3 + 5 + 9 + 1 + 3 = 36。因此,f(I(a))=3⋅36=108f(I(a)) = 3 \cdot 36 = 108。由于 f(a)>f(I(a))f(a) \gt f(I(a)),答案为 “YES”。

在第二个测试用例中,不存在满足 f(a)>f(I(a))f(a) \gt f(I(a)) 的二进制数组 aa,因此答案为 “NO”。

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

首页