解题说明:排序题,水题,注意k=0的情况
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int i,j,k;
int a[12];
int temp;
int sum;
scanf("%d",&k);
for(i=0;i<12;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<12;i++)
{
for(j=i+1;j<12;j++)
{
if(a[i]<a[j])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
if(k==0)
{
printf("0\n");
}
else
{
sum=0;
for(i=0;i<12;i++)
{
sum+=a[i];
if(sum>=k)
{
printf("%d\n",i+1);
break;
}
}
if(i==12)
{
printf("-1\n");
}
}
return 0;
}