Start: Feb, 21, 2019 12:00:00
2018-2019 ACM集训队冬季集训第二次考核
End: Feb, 21, 2019 17:00:00
Time elapsed:
Time remaining:

Problem_ID: G
Result: Accepted
Time: 9ms
Memory: 1096kB
Author: 2018212212041
In contest: 1261

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main() {
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF) {
		int a[1002];
		int flag=0;
		for(int i=0; i<m; i++)scanf("%d",&a[i]);
		sort(a,a+m);
		if(a[0]!=1) {
			printf("NO\n");
			continue;
		}
		long long sum=1;
		for(int i=1; i<m; i++) {

			if(a[i]>sum+1) {
				flag=1;
				break;
			}
			sum+=a[i];
			if(sum>=n)break;
		}
		if(sum<n)flag=1;
		if(flag==1)printf("NO\n");
		else printf("YES\n");
	}
}