Files
python/TangDou/LuoGuBook/P1094.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

22 lines
495 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}