CF1279 A到E

A. New Year Garland
Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.

The local store introduced a new service this year, called “Build your own garland”. So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!

For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: “RGBRBGBGR” (“RGB” being the red, green and blue color, respectively). Note that it’s ok to have lamps of the same color on the ends of the garland.

However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won’t be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.

So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.

Input
The first line contains a single integer t (1≤t≤100) — the number of sets of lamps Polycarp has bought.

Each of the next t lines contains three integers r, g and b (1≤r,g,b≤109) — the number of red, green and blue lamps in the set, respectively.

Output
Print t lines — for each set of lamps print “Yes” if the store workers can build a garland from them and “No” otherwise.

Example
input
3
3 3 3
1 10 2
2 1 1
output
Yes
No
Yes
Note
The first two sets are desribed in the statement.

The third set produces garland “RBRG”, for example.
题意
两个颜色一样的不能放一起,问你讲r个red,g个green,b个blue能不能排成一排。

思路
颜色最多的之间插入其他颜色。
代码

#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 9999999967;
using namespace std;
namespace fastIO {
    inline void input(int& res) {
        char c = getchar();res = 0;int f = 1;
        while (!isdigit(c)) { f ^= c == '-'; c = getchar(); }
        while (isdigit(c)) { res = (res << 3) + (res << 1) + (c ^ 48);c = getchar(); }
        res = f ? res : -res;
    }
    inline ll qpow(ll a, ll b) {
        ll ans = 1, base = a;
        while (b) {
            if (b & 1) ans = (ans * base % mod +mod )%mod;
            base = (base * base % mod + mod)%mod;
            b >>= 1;
        }
        return ans;
    }
}
using namespace fastIO;
const int N = 2e5+5;
int Case,r,g,b;
int a[N];
int main(){
	Case=1;
	input(Case);
	while(Case--){
		input(r),input(g),input(b);
		int maxx=0;
		maxx=max(b,max(r,g));
		if(maxx-1<=r+g+b-maxx) puts("Yes");
		else puts("No");
		
	}
	return 0;
}

B. Verse For Santa
New Year is coming! Vasya has prepared a New Year’s verse and wants to recite it in front of Santa Claus.

Vasya’s verse contains n parts. It takes ai seconds to recite the i-th part. Vasya can’t change the order of parts in the verse: firstly he recites the part which takes a1 seconds, secondly — the part which takes a2 seconds, and so on. After reciting the verse, Vasya will get the number of presents equal to the number of parts he fully recited.

Vasya can skip at most one part of the verse while reciting it (if he skips more than one part, then Santa will definitely notice it).

Santa will listen to Vasya’s verse for no more than s seconds. For example, if s=10, a=[100,9,1,1], and Vasya skips the first part of verse, then he gets two presents.

Note that it is possible to recite the whole verse (if there is enough time).

Determine which part Vasya needs to skip to obtain the maximum possible number of gifts. If Vasya shouldn’t skip anything, print 0. If there are multiple answers, print any of them.

You have to process t test cases.

Input
The first line contains one integer t (1≤t≤100) — the number of test cases.

The first line of each test case contains two integers n and s (1≤n≤105,1≤s≤109) — the number of parts in the verse and the maximum number of seconds Santa will listen to Vasya, respectively.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the time it takes to recite each part of the verse.

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output
For each test case print one integer — the number of the part that Vasya needs to skip to obtain the maximum number of gifts. If Vasya shouldn’t skip any parts, print 0.

Example
input
3
7 11
2 9 1 3 18 1 4
4 35
11 9 10 7
1 8
5
output
2
1
0
Note
In the first test case if Vasya skips the second part then he gets three gifts.

In the second test case no matter what part of the verse Vasya skips.

In the third test case Vasya can recite the whole verse.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值