1
2026-11-06 19:08:06
发布于:广东
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
if (!(cin >> n >> m)) return 0;
vector<int> weights(n);
for (int i = 0; i < n; ++i) {
cin >> weights[i];
}
sort(weights.begin(), weights.end());
int left = 0;
int right = n - 1;
int boats = 0;
while (left <= right) {
if (left == right) {
boats++;
break;
}
if (weights[left] + weights[right] <= m) {
left++;
right--;
boats++;
} else {
right--;
boats++;
}
}
cout << boats << endl;
return 0;
}
这里空空如也


















有帮助,赞一个