解题思路:
贪心,每次选择当前最长的木板即可。
AC代码:
//贪心 每次选择最长的木板
#include<iostream>
#include<stdio.h>
#include<queue>
#include<vector>
#include<functional>
using namespace std;
priority_queue<int> q;//大顶堆
int main() {
int l, n;
while (scanf("%d%d", &l, &n) != EOF) {
int len;
while (!q.empty())q.pop();
for (int i = 1; i <= n; i++) {
scanf("%d", &len);
q.push(len);
}
int now_len = 0, ans = 0;
while (!q.empty() && now_len < l) {
ans++;
now_len += q.top();
q.pop();
}
if (now_len >= l)cout << ans << endl;
else cout << "impossible" << endl;
}
return 0;
}