hdoj 5494 Card Game

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5494

题意:首先一个数t代表测试样例组数  然后两个数n,m 代表数列中有n个数  从中取m个数    给出两组数列  第一组数列代表Soda手中的数字,第二组数代表Beta手中的数,如果从beta手中的数中任意取m个数的和都小于从soda手中任意取出的m个数的和,输出yes否则输出no

题解:求soda手中最小的m个数的和  求beta手中最大m个数的和

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 10000
using namespace std;
int main()
{
	int t,n,m,j,i;
	int suma,sumb;
	int a[MAX],b[MAX];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(i=0;i<n;i++)
		    scanf("%d",&a[i]);
		for(i=0;i<n;i++)
		    scanf("%d",&b[i]);
		sort(a,a+n);
		sort(b,b+n);
		suma=sumb=0;
		for(i=n-1;i>=n-m;i--)
			sumb+=b[i];
		for(i=0;i<m;i++)
		    suma+=a[i];
		if(suma>sumb)
		    printf("YES
");
		else 
		    printf("NO
");
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/tonghao/p/4861581.html