CF1889B.Doremy's Connecting Plan

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Doremy lives in a country consisting of nn cities numbered from 11 to nn, with aia_i people living in the ii-th city. It can be modeled as an undirected graph with nn nodes.

Initially, there are no edges in the graph. Now Doremy wants to make the graph connected.

To do this, she can add an edge between ii and jj if

sum_kinSa_kgeicdotjcdotc,\\sum\_{k \\in S} a\_k \\ge i\\cdot j \\cdot c,

where SS is the set of all the nodes that are currently in the same connected component of either ii or jj, and cc is a given constant.

Can Doremy make the graph connected?

Two nodes (i,j)(i, j) are in the same connected component if there exists a path from ii to jj. A graph is connected if all its nodes are in the same connected component.

Doremy 生活在一个由 nn 座城市组成的国家中,城市编号为 11 到 nn,其中第 ii 座城市有 aia_i 人居住。该国家可建模为一个含 nn 个节点的无向图。

初始时,图中没有任何边。现在 Doremy 希望使该图连通。

为此,她可以在节点 ii 和 jj 之间添加一条边,当且仅当满足以下条件:

∑k∈Sak≥i⋅j⋅c,\sum_{k \in S} a_k \ge i\cdot j \cdot c,

其中 SS 是当前与 ii 或 jj 处于同一连通分量中的所有节点构成的集合,cc 是给定的常数。

Doremy 能否使该图连通?

若节点 (i,j)(i, j) 之间存在一条路径,则称它们处于同一连通分量中;若图中所有节点均属于同一连通分量,则称该图是连通的。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041\le t\le 10^4) — the number of test cases. The description of the test cases follows.

The first line contains two integers nn, cc (2≤n≤2⋅1052\le n\le 2\cdot 10^5, 1≤c≤1061 \le c \le 10^6) — the number of nodes and the constant.

The second line of each test case contains $ n $ integers $ a_1,a_2,\ldots,a_n $ (0≤ai≤10120 \le a_i \le 10^{12}) — the number of people living in the ii-th city.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041\le t\le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 cc(2≤n≤2⋅1052\le n\le 2\cdot 10^5,1≤c≤1061 \le c \le 10^6),分别表示节点数量和常数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai≤10120 \le a_i \le 10^{12}),表示第 ii 个城市中居住的人数。

保证所有测试用例的 nn 之和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, print "YES" (without quotes), if it is possible to make the graph connected, and "NO" (without quotes) otherwise.

You can print letters in any case (upper or lower).

对于每个测试用例,如果可以使图连通,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。

字母大小写均可。

输入输出样例

  • 输入#1

    7
    4 10
    0 20 15 10
    2 1
    1 1
    5 1
    0 1 0 4 199
    5 2
    1 1 3 1 1
    5 5
    5 6 1 10 2
    5 1000000
    1000000000000 1000000000000 1000000000000 1000000000000 1000000000000
    3 1
    0 0 2

    输出#1

    Yes
    Yes
    Yes
    No
    No
    Yes
    No

说明/提示

In the first test case, Doremy can add edges in the following order:

  1. Add (1,2)(1,2). This operation is valid because a1+a2=20≥i⋅j⋅c=20a_1 + a_2 = 20 \ge i\cdot j \cdot c = 20.
  2. Add (1,3)(1,3). This operation is valid because a1+a2+a3=35≥i⋅j⋅c=30a_1 + a_2 + a_3 = 35 \ge i \cdot j \cdot c = 30.
  3. Add (1,4)(1,4). This operation is valid because a1+a2+a3+a4=45≥i⋅j⋅c=40a_1 + a_2 + a_3 + a_4 = 45 \ge i \cdot j \cdot c = 40.

In the second test case, Doremy can add edge (1,2)(1,2) because a1+a2=2≥1⋅2⋅1a_1 + a_2 =2 \ge 1 \cdot 2 \cdot 1. After that, the graph is connected.

In the third test case, Doremy can add edges in the order (5,4)(5,4), (5,3)(5,3), (5,2)(5,2) and (5,1)(5,1).

In the fourth test case, Doremy cannot add any edge at all.

在第一个测试用例中,Doremy 可按以下顺序添加边:

  1. 添加边 (1,2)(1,2)。该操作合法,因为 a1+a2=20≥i⋅j⋅c=20a_1 + a_2 = 20 \ge i\cdot j \cdot c = 20。
  2. 添加边 (1,3)(1,3)。该操作合法,因为 a1+a2+a3=35≥i⋅j⋅c=30a_1 + a_2 + a_3 = 35 \ge i \cdot j \cdot c = 30。
  3. 添加边 (1,4)(1,4)。该操作合法,因为 a1+a2+a3+a4=45≥i⋅j⋅c=40a_1 + a_2 + a_3 + a_4 = 45 \ge i \cdot j \cdot c = 40。

在第二个测试用例中,Doremy 可以添加边 (1,2)(1,2),因为 a1+a2=2≥1⋅2⋅1a_1 + a_2 = 2 \ge 1 \cdot 2 \cdot 1。此后,图即连通。

在第三个测试用例中,Doremy 可按顺序 (5,4)(5,4)、(5,3)(5,3)、(5,2)(5,2) 和 (5,1)(5,1) 添加边。

在第四个测试用例中,Doremy 根本无法添加任何边。

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

首页