提交时间:2023-11-02 13:53:01

运行 ID: 108386

#include <bits/stdc++.h> using namespace std; int a[55],a1[205]; int main() { int x , y , n; cin >> x >> y >> n; if(x >= n) { cout << n; return 0; } for(int i = 1;i <= n; i++) cin >> a1[i]; sort(a1 + 1 , a1 + n + 1); for(int i = 1;i <= n; i++) { for(int j = x; j >= 1; j--) a[j] = min(a[j] + a1[i] - a1[i - 1] , a[j - 1] + 1); a[0] = 1145111451; } cout << a[x] << endl; return 0; }