Educational Codeforces Round 52 (Rated for Div. 2) -C

时间:2022-06-15 03:42:43
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
#define rep(i,j,k) for(long long i=j;i<=k;i++)
#define per(i,j,k) for(long long i=j;i>=k;i--)
using namespace std;
const int N = 2e5+;
ll h[N];
int main(){
long long n,k;
while(~scanf("%lld%lld",&n,&k)){
memset(h,,sizeof(h));
ll maxx=;
ll x;
ll minn=2e5+;
for (int i=;i<=n;i++){
scanf("%lld",&x);
h[x]++;
minn=min(minn,x);
maxx=max(maxx,x);
}
ll sum=;
per(i,maxx-,minn)
h[i]=h[i+]+h[i];
int cnt=;
// cout<<endl;
// rep(i,minn,maxx){
// printf("%d ",h[i]);
// }
// cout<<endl;
per(i,maxx,minn){
if (h[i]+sum>k){
cnt++;
sum=h[i];
}else{
sum=sum+h[i];
}
}
if (sum>h[minn]){
cnt++;
}
printf("%d\n",cnt);
}
return ;
}