日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Social Distance

發(fā)布時(shí)間:2024/5/14 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Social Distance 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Codeforces Round #783 (Div. 2)? ? ?B題

mm?chairs are arranged in a circle sequentially. The chairs are numbered from?00?to?m?1m?1.?nn?people want to sit in these chairs. The?ii-th of them wants at least?a[i]a[i]?empty chairs both on his right and left side.

More formally, if the?ii-th person sits in the?jj-th chair, then no one else should sit in the following chairs:?(j?a[i])modm(j?a[i])modm,?(j?a[i]+1)modm(j?a[i]+1)modm, ...?(j+a[i]?1)modm(j+a[i]?1)modm,?(j+a[i])modm(j+a[i])modm.

Decide if it is possible to sit down for all of them, under the given limitations.

Input

The input consists of multiple test cases. The first line contains a single integer?tt?(1≤t≤5?1041≤t≤5?104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers?nn?and?mm?(2≤n≤1052≤n≤105,?1≤m≤1091≤m≤109) — the number of people and the number of chairs.

The next line contains?nn?integers,?a1a1,?a2a2, ...?anan?(1≤ai≤1091≤ai≤109) — the minimum number of empty chairs, on both sides of the?ii-th person.

It is guaranteed that the sum of?nn?over all test cases will not exceed?105105.

Output

For each test case print "YES" (without quotes) if it is possible for everyone to sit down and fulfil the restrictions, and "NO" (without quotes) otherwise.

You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" will all be recognized as positive answers).

Example

input

Copy

6 3 2 1 1 1 2 4 1 1 2 5 2 1 3 8 1 2 1 4 12 1 2 1 3 4 19 1 2 1 3

output

Copy

NO YES NO YES NO YES

Note

Test case?11:?n>mn>m, so they can not sit down.

Test case?22: the first person can sit?22-nd and the second person can sit in the?00-th chair. Both of them want at least?11?empty chair on both sides, chairs?11?and?33?are free, so this is a good solution.

Test case?33: if the second person sits down somewhere, he needs?22?empty chairs, both on his right and on his left side, so it is impossible to find a place for the first person, because there are only?55?chairs.

Test case?44: they can sit in the?11-st,?44-th,?77-th chairs respectively.

思路:這個(gè)題理解錯(cuò)題了,這個(gè)題問能問否在滿足條件的情況下讓他們都坐下,是我理解錯(cuò)題了,直接去模擬了,導(dǎo)致錯(cuò)了無數(shù)次。讓他們都能坐下要讓最大的去覆蓋較大的,不能去覆蓋最小的,因?yàn)閰^(qū)間的數(shù)量是一定的,最大的一定會(huì)覆蓋兩次,如果讓最大的去覆蓋小的就會(huì)使剩下的區(qū)間由較大的去覆蓋,如果讓小的去覆蓋小的,就會(huì)讓他們的值都是小的,大的覆蓋小的他們的值會(huì)多出來較大的。所以直接排序來讓小的覆蓋小的。

完整代碼:

#include <bits/stdc++.h>using namespace std;#define int long long const int mod=1e9+7;const int N=1e5+10; int a[N];void solve() {int n,m;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+1+n);int ans=0;ans+=(n+a[n]);for(int i=n;i>=2;i--){ans+=a[i];}if(ans<=m)cout<<"YES"<<endl;else cout<<"NO"<<endl; }signed main() {ios_base::sync_with_stdio(false);cin.tie(NULL);int t;cin>>t;while(t--){solve();}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Social Distance的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。