rt.样例一未过:
#include <iostream>
#include <algorithm>
using namespace std;
struct stru {
int val, id;
}arr[200000];
bool cmp(stru a, stru b) {
return a.val > b.val;
}
int ans[200000];
signed main() {
ios::sync_with_stdio(false), cin.tie(), cout.tie();
int n, m, k;
cin >> n >> m >> k;
int sum = 0;
for (int i = 0; i < n; ++i) cin >> arr[i].val, arr[i].id = i, sum += arr[i].val;
int tot = k - sum;
sort(arr, arr + n, cmp);
for (int i = 0; i < n; ++i) {
if (i == 0) {
if (m == n) {
ans[arr[0].id] = 0;
continue;
}
int res = 0;
for (int j = 1; j <= m; ++j) res += arr[0].val + 1 - arr[j].val;
if (res > tot) {
ans[arr[0].id] = 0;
continue;
}
}
if (i < m)
if (arr[i].val - arr[m].val > tot) {
ans[arr[i].id] = 0;
continue;
}
if (i >= m) {
if (arr[m - 1].val - arr[i].val > tot) {
ans[arr[i].id] = -1;
continue;
}
int res = arr[m - 1].val - arr[i].val;
ans[arr[i].id] = res + (tot - res + 1) / 2;
continue;
}
int res = arr[i].val - arr[m].val + 1;
ans[arr[i].id] = (tot - res + 1) / 2;
}
for (int i = 0; i < n; ++i) cout << ans[i] << " ";
return 0;
}