You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
554 B

2 years ago
#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;
}