提交时间:2023-11-03 13:53:50
运行 ID: 108524
#include <bits/stdc++.h> #define endl '\n' using namespace std; int f[114],a[514],n,k,m; int main() { cin >> m >> k >> n; if(m >= n) { cout << n << endl; exit(0); } for(int i = 1;i <= n; i++)cin >> a[i]; sort(a+1 , a+n+1); for(int i = 1;i <= n; i++) { for(int j = m; j >= 1; j--)f[j] = min(f[j]+a[i]-a[i-1], f[j-1]+1); f[0] = 0x3f3f3f3f; } cout << f[m] << endl; return 0; }