列表

详情


NC216208. AllZeroSequence

描述

You are given a sequence consisting of integers A_1,A_2,...,A_N. You can perform some operations on the sequence.
In one operation, you should do the following steps in order :
  • Choose an integer such that and , then decrease A_i. Decrease A_i means changing A_i to A_i-1.
  • For all integer such that and , decrease A_j.
For example, . In one operations, if you choose . After the first step, becomes . After the second step, becomes .

Now you are given an integer , your task is to determine if it is possible to make the sequence consists of   zeros in no more than operations.

输入描述

The first line of the input contains two integers  and , denoting the length of the sequence  and the number of operations.
The second line of the input contains integers .

输出描述

If it is possible to make the sequence  consists of  zeros in no more than  operations, print "Yes", otherwise print "No" (without quote).

示例1

输入:

2 3
2 2

输出:

Yes

示例2

输入:

2 2
2 2

输出:

No

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 56ms, 内存消耗: 1168K, 提交时间: 2020-12-28 10:38:42

#include<bits/stdc++.h>
using namespace std;
int n,k,a[200010];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int s=k-n;
	for(int i=1;i<=n;i++){
		if(a[i]-i-(k-n)>0)
			s-=a[i]-i-(k-n);
		if(s<0) return printf("No"),0;
	}
	printf("Yes");
	return 0;
}

上一题