/**********
Author Smile
思想就是 贪心 + 双指针
贪心顾名思义,双指针就是见风使舵(少什么,加什么)
https://vjudge.csgrandeur.cn/contest/477345#problem/A
**********/
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e4 + 10;
ll n, m;
ll ans = 0;
ll countt = 0;
ll w[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
cin >> w[i];
}
sort(w + 1, w + 1 + n);
int cnt = n;
int temp = n;
for (int i = 1; i < cnt;)
{
for (int j = cnt; j > i; j = cnt)
{
if (w[j] + w[i] <= m)
{
ans++;
countt += 2;
cnt--;
i++;
break;
}
else
{
ans++;
countt++;
cnt--;
}
}
}
ans += n - countt;
cout << ans << endl;
return 0;
}
贪心 + 双指针
最新推荐文章于 2022-07-12 14:50:25 发布