编程语言
首页 > 编程语言> > 算法训练 纪念品分组

算法训练 纪念品分组

作者:互联网

#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
bool cmp(int a,int b){
	return a<b;
}
int main(){
	int w,n,ifir,iend,tol=0;
	scanf("%d%d",&w,&n);
	int value[n];
	ifir=0,iend=n-1;
	for(int i=0;i<n;i++){
		scanf("%d",&value[i]);
	}
	sort(value,value+n,cmp);
	while(ifir<=iend){
		//TODO double point 
		if(value[ifir]+value[iend]<=w&&(ifir!=iend)){
			tol++,ifir++,iend--;
		}else{
			tol++,iend--;
		}
	}
	printf("%d\n",tol);
	return 0;
}

标签:std,纪念品,return,int,namespace,算法,分组,bool,include
来源: https://www.cnblogs.com/jeseesmith/p/15849345.html