https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1432
每次找最大的和最小的放。
如果放不下就最大的单独放。
因为如果出现船多,只有两种情况。
① 很多小船,他们彼此用两个,浪费了很大的空间。
② 很多大船,他们彼此用两个,而大型的船要独占一个。
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
/* 最大的和最小
*/
const int maxn=1e5;
int a[maxn];
int main()
{ int m,k;
int ans=0;
scanf("%d%d",&m,&k);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
sort(a,a+m);
int max1=m-1;int min1=0;
while(1){
if(max1<min1)
break;
else if(max1==min1)
{ans++;break;
}
else if(a[max1]+a[min1]<=k){
max1--;
min1++;
ans++;
}
else {
max1--;
ans++;
}
}
printf("%d\n",ans);
return 0;
}