AtCoder Beginner Contest 161 B Popular Vote Quick Sort + Divide + Mod

AtCoder Beginner Contest 161 The   number of contestants is 9927   fast, see all questions 5 minutes after the start of the contest

AtCoder Beginner Contest 161 B Popular Vote Quick Sort + Divide + Mod

See https://blog.csdn.net/mrcrack/article/details/104454762 for the general catalog

Online evaluation address https://atcoder.jp/contests/abc161/tasks/abc161_b

Topic:

M stands for optional quantity. If all M satisfy the constraints, output Yes, otherwise, output No.

The basic idea:

Sort by the number of votes from largest to smallest. After sorting, select the Mth number of votes to see if the constraints are met.

It should be noted that when dividing by 4M, there are two cases to be considered: divisible by, not divisible by.

#include <cstdio>
#include <algorithm>
using namespace std;
int a[110];
int cmp(int a,int b){
	return a>b;
}
int main(){
	int n,m,i,b=0,c;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",&a[i]),b+=a[i];
	sort(a+1,a+1+n,cmp);
	c=4*m;
	if(b%c==0)b/=c;
	else b=b/c+1;
	if(a[m]>=b)printf("Yes\n");
	else printf("No\n");
	return 0;
}

 

Published 660 original articles · praised 562 · 480,000 views

Guess you like

Origin blog.csdn.net/mrcrack/article/details/105321940