Codeforces Round 1113 (Div. 2)
E
休息的借口
Excuse for Breaks
Codeforces
2000
原题
← DF →

休息的借口AI (CI翻译)

You are given three integers $n$, $m$, and $d$, and two arrays $p_1, p_2, \ldots, p_m$ and $r_1, r_2, \ldots, r_m$. The array $p$ is strictly increasing.

给定三个整数 $n$、$m$ 和 $d$,以及两个数组 $p_1, p_2, \ldots, p_m$ 和 $r_1, r_2, \ldots, r_m$。数组 $p$ 严格递增。AI (CI翻译)

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

对于任意长度为正的有限二进制数组 $a$(因此 $|a|$ 不一定等于 $n$),按照以下伪代码定义其值 $f(a)$:AI (CI翻译)

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

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
AI (CI翻译)

Here, "

其中,“AI (CI翻译)

:=

:=AI (CI翻译)

" denotes the assignment operation.

”表示赋值操作。AI (CI翻译)

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

令 $I(a)$ 表示长度为 $|a|$ 的数组 $[1,1,\ldots,1]$。换句话说,$I(a)$ 由 $|a|$ 个 $1$ 组成。AI (CI翻译)

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

判断是否存在一个二进制数组 $a$(只包含 $0$ 和 $1$),使得 $f(a) \gt f(I(a))$。AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

每个输入包含多组测试用例。第一行包含测试用例数 $t$($1 \le t \le 2000$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains three integers $n$, $m$, and $d$ ($1 \le n \le 10^9$, $0 \le m \le 2000$, $0 \le d \le 10^9$).

每个测试用例的第一行包含三个整数 $n$、$m$ 和 $d$($1 \le n \le 10^9$,$0 \le m \le 2000$,$0 \le d \le 10^9$)。AI (CI翻译)

The $i$-th of the next $m$ lines contains two integers $p_i$ and $r_i$ ($1 \le p_i \le n$, $1 \le r_i \le 10^9$).

接下来的 $m$ 行中,第 $i$ 行包含两个整数 $p_i$ 和 $r_i$($1 \le p_i \le n$,$1 \le r_i \le 10^9$)。AI (CI翻译)

The array $p$ is strictly increasing.

数组 $p$ 严格递增。AI (CI翻译)

It is guaranteed that the sum of $m$ over all test cases does not exceed $2000$.

保证所有测试用例的 $m$ 之和不超过 $2000$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

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

对于每个测试用例,如果存在满足条件的二进制数组 $a$,输出“YES”,否则输出“NO”。AI (CI翻译)

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.

答案可以使用任意大小写形式。例如,字符串“yEs”、“yes”、“Yes”和“YES”都会被识别为肯定回答。AI (CI翻译)

Note

说明

AI (CI翻译)

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]$。AI (CI翻译)

The array $a$ contains $16$ ones, so the total contribution of $d$ is $16 \cdot 3 = 48$. Its runs of consecutive ones have lengths $9$, $4$, and $3$. The corresponding total rewards are $32$, $15$, and $14$, respectively. Therefore, $f(a) = 48 + 32 + 15 + 14 = 109$.

数组 $a$ 中有 $16$ 个 $1$,因此 $d$ 的总贡献为 $16 \cdot 3 = 48$。其中连续 $1$ 的段长度分别为 $9$、$4$ 和 $3$,对应的奖励总和分别为 $32$、$15$ 和 $14$。因此,$f(a) = 48 + 32 + 15 + 14 = 109$。AI (CI翻译)

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

此外,$I(a)$ 由 $18$ 个 $1$ 组成。在计算 $f(I(a))$ 时,这些 $1$ 构成三个完整的、长度为 $6$ 的块,每个块的贡献为 $6 \cdot 3 + 5 + 9 + 1 + 3 = 36$。因此,$f(I(a)) = 3 \cdot 36 = 108$。由于 $f(a) \gt f(I(a))$,答案为“YES”。AI (CI翻译)

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

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

样例

Input #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
Output #1
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2248E
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
贪心
数学
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。