poj 3627 Bookshelf

poj 3627 Bookshelf

/*
排序就行 
*/
#define LOCAL
#include<iostream>
#define N 20001
using namespace std;
int cow[N];
int cmp(const void *p,const void *q)
{return (*(int *)q-*(int *)p);}
int main()
{
#ifdef LOCAL
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
#endif
    
    
    int n,i;
    double b,sum;      //double消灭long long ! 
    while(cin>>n>>b)
    {
             for(i=0;i<n;i++)
                  cin>>cow[i];
             qsort(cow,n,sizeof(int),cmp);
             sum=0;
             i=0;
             while(sum<b)
             {
                 sum+=cow[i];
                 i++;              
             }       
             cout<<i<<endl;                              
    }
    return 0;
}

发表回复