This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
int w, n;
const int N = 30010;
int a[N];
//双指针
int h = 1, t = n, cnt;
int main() {
cin >> w >> n;
for (int i = 1; i <= n; i++)cin >> a[i];
sort(a + 1, a + 1 + n);
//双指针,太聪明的办法了
while (h <= t)
if (a[t] + a[h] > w) cnt++, t--; //装不下的话,a[t]独立成组
else cnt++, t--, h++;//能装下的话,a[t]+a[h]为一组
cout << cnt << endl;
return 0;
}