[贪心]1432独木舟
题目
![在这里插入图片描述 [贪心]1432独木舟_i++](https://file.cfanz.cn/uploads/png/2022/11/25/11/65919c61f3.png)
思路
最重的和最小的配,大的带不动的单独一组
代码
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long LL;
typedef pair<int,int> PII;
/*DATA & KEY
*/
int T;
const int N=1e4+10;
int a[N];
void solve()
{
//NEW DATA CLEAN
//NOTE!!!
LL n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+1+n);
int i=1,j=n;
int ans=0;
while(i<j)
{
if(a[i]+a[j]<=m)
{
ans++;
i++;
j--;
n-=2;
}
else
{
ans++;
j--;
n--;
}
}
ans+=n;
cout<<ans<<endl;
}
int main()
{
// scanf("%d",&T);
// while(T--)solve(T);
solve();
return 0;
}










