#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool a[40000];
int main()
{
int n;
cin >> n;
int w;
cin >> w;
vector<int>p(w);
for (int i = 0; i < w; i++)
{
cin >> p[i];
}
sort(p.begin(), p.end());
reverse(p.begin(), p.end());
int x = 0;
int j = w - 1;
for (int i = 0; i <w; i++)
{
if (a[i] == 0&&i!=j&&j>=0)
{
int y = p[i] + p[j];
if (y <= n)
{
a[i] = 1;
a[j] = 1;
x += 1;
j -= 1;
}
else if (y > n && p[i] < n)
{
a[i] = 1;
x += 1;
}
}
}
for (int i = 0; i < w; i++)
{
if (a[i] == 0)
{
x += 1;
}
}
cout << x << endl;
}
洛谷 P1094 [NOIP2007 普及组] 纪念品分组
最新推荐文章于 2024-08-20 10:48:49 发布