Stable Groups - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
将n个数分组 ,使得每个组中相邻的两个数之间的差小于x,有k个任意数可以使用,最少只需多少组就可以分完所有数
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#define x first
#define y second
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef pair<int,int> PII;
typedef pair<char,int> PCI;
typedef long long LL;
//typedef __int128 i128;
typedef unsigned long long ULL;
const int N=2e5+10,INF = 1e9 ;
const double eps = 1e-7;
LL n,k,x;
LL a[N];
LL b[N];
void solve()
{
cin >> n >> k >> x;
LL cnt =1; // 刚开始只有一个组
for(int i=1;i<=n; i++ ) cin >> a[i];
sort(a+1,a+n+1);
for(int i=2;i<=n;i ++)
b[i-1] = a[i] - a[i-1 ];
sort(b+1,b+n);
for(int i=1;i<n;i ++ )
if(b[i] > x )
{
// b[i] <= x ===> b[i] < x + 1 == b[i] - x < x 的情况就不用k
if(k >= (b[i] - 1 ) /x )
k -= (b[i] - 1) /x ;// 每隔x个位置放一个新的人
else cnt ++ ;
}
cout << cnt << endl;
}
int main()
{
// freopen("1.txt","r",stdin);
ios
LL T=1;
// cin>>T;
while(T -- )
{
solve();
}
return 0;
}