首页 > 代码库 > 算法竞赛入门经典(第八章)

算法竞赛入门经典(第八章)

 

习题8-1 Uva1149  11.8  

#include <iostream>#include <algorithm>using namespace std;int main(){	int n, m, mi;	int w[100005];	int num;	int l, r;	cin>>n>>m;	for(int i = 1; i <= n; i++)	{		cin>>w[i];	}	sort(w+1, w+n+1);	l = 1 , r = n;	num = 0;	while(l!=r)	{		mi = m;		if(w[l] <= mi)		{			mi-=w[l];						l++;		}			else		{			cout<<"No Answer!"<<endl;			return 0;		}		if(w[r] <= mi)	r--;		num++;	}	cout<<num<<endl;	return 0;} 

  

算法竞赛入门经典(第八章)