CF1285B.Just Eat It!

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Today, Yasser and Adel are at the shop buying cupcakes. There are nn cupcake types, arranged from 11 to nn on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type ii is an integer aia_i. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.

Yasser, of course, wants to try them all, so he will buy exactly one cupcake of each type.

On the other hand, Adel will choose some segment [l,r][l, r] (1≤l≤r≤n)(1 \le l \le r \le n) that does not include all of cupcakes (he can't choose [l,r]=[1,n][l, r] = [1, n]) and buy exactly one cupcake of each of types l,l+1,…,rl, l + 1, \dots, r.

After that they will compare the total tastiness of the cupcakes each of them have bought. Yasser will be happy if the total tastiness of cupcakes he buys is strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice.

For example, let the tastinesses of the cupcakes be [7,4,−1][7, 4, -1]. Yasser will buy all of them, the total tastiness will be 7+4−1=107 + 4 - 1 = 10. Adel can choose segments [7],[4],[−1],[7,4][7], [4], [-1], [7, 4] or [4,−1][4, -1], their total tastinesses are 7,4,−1,117, 4, -1, 11 and 33, respectively. Adel can choose segment with tastiness 1111, and as 1010 is not strictly greater than 1111, Yasser won't be happy :(

Find out if Yasser will be happy after visiting the shop.

今天,Yasser 和 Adel 到商店买纸杯蛋糕。货架上共有 nn 种纸杯蛋糕,编号从 11 到 nn 依次排列,且每种类型均有无限多个。第 ii 种纸杯蛋糕的美味度为整数 aia_i。其中既有美味的蛋糕,也有难吃的蛋糕,因此美味度可为正数、零或负数。

Yasser 当然想尝遍所有种类,因此他会恰好购买每种类型各一个纸杯蛋糕。

而 Adel 则会选择某个区间 [l,r][l, r](满足 1≤l≤r≤n1 \le l \le r \le n),但该区间不能包含全部种类(即不允许选择 [l,r]=[1,n][l, r] = [1, n]),并恰好购买类型编号为 l,l+1,…,rl, l + 1, \dots, r 的每种各一个纸杯蛋糕。

之后,他们将比较各自所购纸杯蛋糕的总美味度。若 Yasser 所购纸杯蛋糕的总美味度严格大于 Adel 所购纸杯蛋糕的总美味度(无论 Adel 如何选择区间),则 Yasser 将感到开心。

例如,设纸杯蛋糕的美味度为 [7,4,−1][7, 4, -1]。Yasser 将购买全部三种,总美味度为 7+4−1=107 + 4 - 1 = 10。Adel 可选的区间有 [7],[4],[−1],[7,4][7], [4], [-1], [7, 4] 或 [4,−1][4, -1],对应总美味度分别为 7,4,−1,117, 4, -1, 11 和 33。Adel 可选择总美味度为 1111 的区间;而由于 1010 并不严格大于 1111,Yasser 将不会开心 :(

请判断:Yasser 在逛完这家店后是否会开心。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains nn (2≤n≤1052 \le n \le 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (−109≤ai≤109-10^9 \le a_i \le 10^9), where aia_i represents the tastiness of the ii-th type of cupcake.

It is guaranteed that the sum of nn over all test cases doesn't exceed 10510^5.

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

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(−109≤ai≤109-10^9 \le a_i \le 10^9),其中 aia_i 表示第 ii 种纸杯蛋糕的美味程度。

保证所有测试用例中 nn 的总和不超过 10510^5。

输出格式

For each test case, print "YES", if the total tastiness of cupcakes Yasser buys will always be strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice. Otherwise, print "NO".

对于每个测试用例,如果无论 Adel 如何选择,Yasser 所购买的纸杯蛋糕的总美味度都严格大于 Adel 所购买的纸杯蛋糕的总美味度,则输出 "YES";否则输出 "NO"。

输入输出样例

  • 输入#1

    3
    4
    1 2 3 4
    3
    7 4 -1
    3
    5 -5 5

    输出#1

    YES
    NO
    NO

说明/提示

In the first example, the total tastiness of any segment Adel can choose is less than the total tastiness of all cupcakes.

In the second example, Adel will choose the segment [1,2][1, 2] with total tastiness 1111, which is not less than the total tastiness of all cupcakes, which is 1010.

In the third example, Adel can choose the segment [3,3][3, 3] with total tastiness of 55. Note that Yasser's cupcakes' total tastiness is also 55, so in that case, the total tastiness of Yasser's cupcakes isn't strictly greater than the total tastiness of Adel's cupcakes.

在第一个例子中,Adel 能选择的任意区间的总美味度均小于所有纸杯蛋糕的总美味度。

在第二个例子中,Adel 将选择区间 [1,2][1, 2],其总美味度为 1111,该值不小于所有纸杯蛋糕的总美味度(即 1010)。

在第三个例子中,Adel 可以选择区间 [3,3][3, 3],其总美味度为 55。注意,Yasser 的纸杯蛋糕总美味度也为 55,因此此时 Yasser 的纸杯蛋糕总美味度并不严格大于 Adel 的纸杯蛋糕总美味度。

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

首页