WHY????????????
2025-06-15 17:45:58
发布于:浙江
6阅读
0回复
0点赞
我哪儿错了?WHY?????????????
为什么??????????????????
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, K;
cin >> n >> K;
vector<ll> A(n);
for (int i = 0; i < n; ++i) {
cin >> A[i];
}
sort(A.begin(), A.end());
priority_queue<ll, vector<ll>, greater<ll>> pq;
for (int i = 1; i < n; ++i) {
pq.push(A[i] - A[i-1]);
}
ll res = 0;
int days_used = 0;
while (days_used < K && !pq.empty()) {
res += pq.top();
pq.pop();
days_used++;
}
cout << res << endl;
return 0;
}
这里空空如也
有帮助,赞一个