|
| 1 | +/* |
| 2 | + Idea: |
| 3 | + - We can reduce `k` if we try to remove animals from the smallest number of |
| 4 | + examinations to the biggest. |
| 5 | + - Then we can reduce `k` even more, we know that in the current state we |
| 6 | + cannot remove any animal, but we can remove some examinations from the |
| 7 | + animals by divide the remaining `k` by the remaining animals. |
| 8 | + - Finally, the remaining `k` will be less than 10^5, so we can brute force |
| 9 | + it. |
| 10 | +*/ |
| 11 | + |
| 12 | +#include <bits/stdc++.h> |
| 13 | + |
| 14 | +using namespace std; |
| 15 | + |
| 16 | +int const N = 1e5 + 10; |
| 17 | +int n, a[N]; |
| 18 | +long long k, to, tt; |
| 19 | +vector<int> v; |
| 20 | +map<int, int> mp; |
| 21 | +queue<pair<int, int> > q; |
| 22 | + |
| 23 | +int main() { |
| 24 | + scanf("%d %lld", &n, &k); |
| 25 | + for(int i = 0; i < n; ++i) { |
| 26 | + scanf("%d", a + i); |
| 27 | + v.push_back(a[i]); |
| 28 | + ++mp[a[i]]; |
| 29 | + to += a[i]; |
| 30 | + } |
| 31 | + |
| 32 | + if(to < k) { |
| 33 | + puts("-1"); |
| 34 | + return 0; |
| 35 | + } |
| 36 | + |
| 37 | + sort(v.begin(), v.end()); |
| 38 | + v.resize(unique(v.begin(), v.end()) - v.begin()); |
| 39 | + |
| 40 | + int cnt = n; |
| 41 | + for(int i = 0, prv = 0; i < v.size(); ++i) { |
| 42 | + if(k >= 1ll * (v[i] - prv) * cnt) { |
| 43 | + k -= 1ll * (v[i] - prv) * cnt; |
| 44 | + tt += (v[i] - prv); |
| 45 | + cnt -= mp[v[i]]; |
| 46 | + } else |
| 47 | + break; |
| 48 | + |
| 49 | + prv = v[i]; |
| 50 | + } |
| 51 | + |
| 52 | + for(int i = 0; i < n; ++i) |
| 53 | + a[i] -= tt, a[i] = max(0, a[i]); |
| 54 | + |
| 55 | + if(cnt == 0) |
| 56 | + return 0; |
| 57 | + |
| 58 | + int rem = k / cnt; |
| 59 | + k -= 1ll * rem * cnt; |
| 60 | + |
| 61 | + for(int i = 0; i < n; ++i) |
| 62 | + if(a[i] > 0) |
| 63 | + a[i] -= rem, q.push({a[i], i + 1}); |
| 64 | + |
| 65 | + for(int i = 0; i < k; ++i) { |
| 66 | + pair<int, int> p = q.front(); |
| 67 | + q.pop(); |
| 68 | + if(--p.first == 0) |
| 69 | + continue; |
| 70 | + q.push(p); |
| 71 | + } |
| 72 | + |
| 73 | + while(!q.empty()) { |
| 74 | + printf("%d ", q.front().second); |
| 75 | + q.pop(); |
| 76 | + } |
| 77 | + puts(""); |
| 78 | + |
| 79 | + return 0; |
| 80 | +} |
0 commit comments