//题目1436:Repair the Wall
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 610;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int iLen, arr[MAXN], n, i, iSumLen, iNum;
while(~scanf("%d %d", &iLen, &n))
{
bool flag = false;
for(i = 0; i < n; ++i)
scanf("%d", &arr[i]);
sort(arr, arr+n, cmp);
iSumLen = 0, iNum = 0;
for(i = 0; i < n; ++i)
{
iSumLen += arr[i];
iNum++;
if(iSumLen >= iLen)
{
flag = true;
break;
}
}
if(flag)
printf("%d\n", iNum);
else
printf("impossible\n");
}
return 0;
}
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[600];
int main() {
int l,n,i;
while(scanf("%d %d",&l,&n)!=EOF) {
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int count = 0;
sort(a,a+n);
i = n-1;
while(i>=0&&l>=a[i]) {
l -= a[i--];
count++;
}
if(i<0&&l>0)
printf("impossible\n");
else if(l==0)
printf("%d\n",count);
else if(l>0&&i>=0)
printf("%d\n",count+1);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 610;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int iLen, arr[MAXN], n, i, iSumLen, iNum;
while(~scanf("%d %d", &iLen, &n))
{
bool flag = false;
for(i = 0; i < n; ++i)
scanf("%d", &arr[i]);
sort(arr, arr+n, cmp);
iSumLen = 0, iNum = 0;
for(i = 0; i < n; ++i)
{
iSumLen += arr[i];
iNum++;
if(iSumLen >= iLen)
{
flag = true;
break;
}
}
if(flag)
printf("%d\n", iNum);
else
printf("impossible\n");
}
return 0;
}
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[600];
int main() {
int l,n,i;
while(scanf("%d %d",&l,&n)!=EOF) {
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int count = 0;
sort(a,a+n);
i = n-1;
while(i>=0&&l>=a[i]) {
l -= a[i--];
count++;
}
if(i<0&&l>0)
printf("impossible\n");
else if(l==0)
printf("%d\n",count);
else if(l>0&&i>=0)
printf("%d\n",count+1);
}
return 0;
}