贪心-最优装载有关问题

贪心-最优装载问题
//最优装载
#include<iostream>
using namespace std;
template <class Type>
void loading(int x[],Type w[],Type c,int n)
{
   int *t=new int [n+1];
   sort(w,t,n);
   for(int i=1;i<=n;i++)
   x[i]=0;
   for(int i=1;i<=n&&w[t[i]]<=c;i++)
   {
      x[t[i]]=1;
 c-=w[t[i]];
   }
   for(int i=1;i<=n;i++)
   cout<<x[i]<<" "<<endl;
}
int main()
{
   int x[100];   //x[i]=0,不装入;x[i]=1,装入
   int w[100];//重量
   int c;//承载量
   int n;
   while(cin>>n)
   {
      cin>>c;
      for(int i=1;i<=n;i++)
      cin>>w[i];
 loading(x,w,c,n);
   }
}