[贪心]1432独木舟

题目

[贪心]1432独木舟_i++

思路

最重的和最小的配,大的带不动的单独一组

代码

#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;
}