533
Analysis: first, we should sort by size from small to large. After sorting, we thought that if the smallest weight cannot be the same as the largest weight, then the heavyweight will have to take a boat by themselves. This question can simulate this idea and constantly screen outSit-togetherOnly one person can sit in a few pairs and remove them. That is, after sorting, let the smallest and largest addition compare with the ship weight limit. If possible, both sides will be reduced by 1; otherwise, right minus 1, and sum ++; then, and then, the answer will come out.
DetailsCodeAs follows:
# Include <stdio. h ># include <algorithm> using namespace STD; int main () {int t, n, m, I, sum, J, s [301]; scanf ("% d", & T); While (t --) {scanf ("% d", & M, & N); for (I = 0; I <n; I ++) scanf ("% d", & S [I]); sort (S, S + n); for (I = 0, j = n-1, sum = 0;) {If (j <I) break; If (j = I) {sum ++; break ;} if (s [I] + s [J]> m) {sum ++; j --; continue;} If (s [I] + s [J] <= m) {sum ++; I ++; j --; Continue ;}} printf ("% d \ n", sum );}}