- 整数分组
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int f[5010][5010];int w[5010];int n,m;cin>>n>>m;for (int i=1;i<=n;i++) cin>>w[i];sort(w+1,w+n+1);for (int i=1,j=1;i<=n;i++){while (w[i]-w[j]>5) j++;for (int k=1;k<=m;k++){f[i][k] = max(f[i-1][k],f[j-1][k-1]+(i-j+1));}}cout<<f[n][m];return 0;
}