Social Distance
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 3output
Copy
NO YES NO YES NO YESNote
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.
思路:這個題理解錯題了,這個題問能問否在滿足條件的情況下讓他們都坐下,是我理解錯題了,直接去模擬了,導致錯了無數次。讓他們都能坐下要讓最大的去覆蓋較大的,不能去覆蓋最小的,因為區間的數量是一定的,最大的一定會覆蓋兩次,如果讓最大的去覆蓋小的就會使剩下的區間由較大的去覆蓋,如果讓小的去覆蓋小的,就會讓他們的值都是小的,大的覆蓋小的他們的值會多出來較大的。所以直接排序來讓小的覆蓋小的。
完整代碼:
#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; }總結
以上是生活随笔為你收集整理的Social Distance的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 判断中英文、数字及全角半角
- 下一篇: 【虹科案例】虹科任意波形发生器在量子计算