NOJ [1293] Porter Cai

。。。妈蛋,今天完全没动力想题目啊,难道是老蔡走了的缘故,老蔡

...贪心题,不难


#include<stdio.h>
#include<algorithm>
using namespace std;

int num[10010];
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,w;
	while(~scanf("%d%d",&n,&w))
	{
		int i,j;
		int ans=0;
		int temp,len=0;
		while(n--)
		{
			scanf("%d",&temp);
			if(temp>=w)
			 ans++;
		    else
	    	 num[len++]=temp;
		}
		sort(num,num+len,cmp);
		i=0;
		j=len-1;
		while(i<=j)
		{
			if(i!=j)
			{
				if(num[i]+num[j]<=w)
				{
					ans++;
					i++;
					j--;
				}
				else
				{
					ans++;
					i++;
				}
			}
			else
			{
				ans++;
				break;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


你可能感兴趣的:(NOJ [1293] Porter Cai)