1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| #include <bits/stdc++.h>
#define int int64_t
const int kMaxN = 1e5 + 5;
int n, m, k; int a[kMaxN], op[kMaxN], pos[kMaxN], val[kMaxN], p0[kMaxN], p1[kMaxN]; std::pair<int, int> mx[kMaxN]; bool vis[kMaxN]; std::vector<int> sum[kMaxN]; std::vector<std::pair<int, int>> vec[kMaxN][2];
struct frac { int x, y;
frac(int _x = 0, int _y = 1) : x(_x), y(_y) {} friend bool operator <(frac a, frac b) { return (__int128_t)a.x * b.y < (__int128_t)a.y * b.x; } };
int getsum(int x, int k) { if (!~k) return a[x]; else return a[x] + sum[x][k]; }
void dickdreamer() { std::cin >> n >> m >> k; for (int i = 1; i <= n; ++i) std::cin >> a[i]; for (int i = 1; i <= m; ++i) { std::cin >> op[i] >> pos[i] >> val[i]; if (op[i] == 1) mx[pos[i]] = std::max(mx[pos[i]], {val[i], i}); else if (op[i] == 2) vec[pos[i]][0].emplace_back(val[i], i); else vec[pos[i]][1].emplace_back(val[i], i); } std::priority_queue<std::tuple<frac, int, int, int>> qq; int cnt = 0; for (int i = 1; i <= n; ++i) { if (mx[i].first > a[i]) vec[i][0].emplace_back(mx[i].first - a[i], mx[i].second); std::sort(vec[i][0].begin(), vec[i][0].end(), std::greater<std::pair<int, int>>()); std::sort(vec[i][1].begin(), vec[i][1].end(), std::greater<std::pair<int, int>>()); sum[i].resize(vec[i][0].size()); for (int j = 0; j < (int)vec[i][0].size(); ++j) { sum[i][j] = (!j ? 0 : sum[i][j - 1]) + vec[i][0][j].first; } for (auto [x, id] : vec[i][0]) vis[id] = 1; for (auto [x, id] : vec[i][1]) vis[id] = 1; p0[i] = (int)vec[i][0].size() - 1; p1[i] = (int)vec[i][1].size() - 1; if (~p0[i]) qq.emplace(frac(getsum(i, p0[i] - 1), getsum(i, p0[i])), i, 0, vec[i][0][p0[i]].second); if (~p1[i]) qq.emplace(frac(1, vec[i][1][p1[i]].first), i, 1, vec[i][1][p1[i]].second); cnt += vec[i][0].size() + vec[i][1].size(); } for (; cnt > k; --cnt) { auto [f, i, o, id] = qq.top(); qq.pop(); vis[id] = 0; if (!o) { --p0[i]; if (~p0[i]) qq.emplace(frac(getsum(i, p0[i] - 1), getsum(i, p0[i])), i, 0, vec[i][0][p0[i]].second); } else { --p1[i]; if (~p1[i]) qq.emplace(frac(1, vec[i][1][p1[i]].first), i, 1, vec[i][1][p1[i]].second); } } std::vector<int> vec[3]; for (int i = 1; i <= m; ++i) { if (vis[i]) vec[op[i] - 1].emplace_back(i); } std::cout << cnt << '\n'; for (auto x : vec[0]) std::cout << x << ' '; for (auto x : vec[1]) std::cout << x << ' '; for (auto x : vec[2]) std::cout << x << ' '; }
int32_t main() { #ifdef ORZXKR freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); int T = 1; while (T--) dickdreamer(); return 0; }
|