Files
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

26 lines
554 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 30010;
int n, m;
int w[N];
int main() {
// m:每组纪念品价格之和的上限
// n:购来的纪念品的总件数
cin >> m >> n;
for (int i = 0; i < n; i++) cin >> w[i]; // 表示所对应纪念品的价格
// 将价格由小到大排序
sort(w, w + n);
int res = 0;
// 双指针对撞
for (int i = 0, j = n - 1; i <= j; j--) {
if (w[i] + w[j] <= m) i++;
res++;
}
cout << res << endl;
return 0;
}