Just Eat It!

题目

Today, Yasser and Adel are at the shop buying cupcakes. There are n cupcake types, arranged from 1 to n on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type i is an integer ai. 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] (1≤l≤r≤n) that does not include all of cupcakes (he can’t choose [l,r]=[1,n]) and buy exactly one cupcake of each of types l,l+1,…,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]. Yasser will buy all of them, the total tastiness will be 7+4−1=10. Adel can choose segments [7],[4],[−1],[7,4] or [4,−1], their total tastinesses are 7,4,−1,11 and 3, respectively. Adel can choose segment with tastiness 11, and as 10 is not strictly greater than 11, Yasser won’t be happy 😦

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

Input

Each test contains multiple test cases. The first line contains the number of test cases t ( 1 ≤ t ≤ 1 0 4 ) t(1≤t≤10^4) t(1t104). The description of the test cases follows.

The first line of each test case contains n ( 2 ≤ n ≤ 1 0 5 ) n(2≤n≤10^5)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您的问题是关于Java编程的。我会尽力回答。以下是可能的解决方案: 1. 首先,您需要创建四个类:Chicken、Duck、Fish、AppleOrange、BreadChocolate。这些类都需要实现一个接口Edible,其中包含一个方法howToEat()。 2. 然后,您需要创建一个Test类,并在其main方法中创建一个数组,用来保存上述五个类的实例。 3. 接下来,您需要创建一个静态方法eat_food(Edible food),该方法接受一个可以食用的类作为参数,并在方法内调用howToEat方法。 4. 最后,在main方法中,您可以遍历数组,并将数据组中的对象依次传入eat_food方法中,以查看运行结果。 以下是可能的代码实现: ``` public interface Edible { void howToEat(); } public class Chicken implements Edible { public void howToEat() { System.out.println("Fry it!"); } } public class Duck implements Edible { public void howToEat() { System.out.println("Roast it!"); } } public class Fish implements Edible { public void howToEat() { System.out.println("Grill it!"); } } public class AppleOrange implements Edible { public void howToEat() { System.out.println("Just eat it!"); } } public class BreadChocolate implements Edible { public void howToEat() { System.out.println("Bite it!"); } } public class Test { public static void eat_food(Edible food) { food.howToEat(); } public static void main(String[] args) { Edible[] foods = {new Chicken(), new Duck(), new Fish(), new AppleOrange(), new BreadChocolate()}; for (Edible food : foods) { eat_food(food); } } } ``` 输出结果为: ``` Fry it! Roast it! Grill it! Just eat it! Bite it! ``` 希望这个解决方案能够解决您的问题。如果您有任何其他问题,请随时问我!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值