NC216208. AllZeroSequence
描述
输入描述
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; }