Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long llint;
- const int MAXN = 500005;
- llint n, w, sum;
- llint s[MAXN], q[MAXN], p[MAXN], cnt[MAXN], val[MAXN];
- priority_queue < pair <llint, int> > st;
- bool cmp (int x, int y) {
- return q[x] * s[y] > q[y] * s[x];
- }
- bool cmp2 (int x, int y) {
- if (cnt[x] != cnt[y]) return cnt[x] > cnt[y];
- return val[x] * s[x] * q[y] < val[y] * s[y] * q[x];
- }
- void dodaj (int x, bool flg) {
- st.push(make_pair(q[x], x));
- sum += q[x];
- while (sum * s[x] > w * q[x]) {
- sum -= st.top().first;
- st.pop();
- }
- cnt[x] = st.size();
- val[x] = sum;
- if (flg) {
- cout << cnt[x] << endl;
- while (!st.empty()) {
- cout << st.top().second << endl;
- st.pop();
- }
- }
- }
- int main () {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cin >> n >> w;
- for (int i=1; i<=n; i++) {
- cin >> s[i] >> q[i];
- p[i] = i;
- }
- sort(p + 1, p + 1 + n, cmp);
- int mx = p[1];
- for (int i=1; i<=n; i++) {
- dodaj(p[i], 0);
- //cout << "bla " << p[i] << " " << cnt[p[i]] << endl;
- if (cmp2(p[i], mx)) {
- mx = p[i];
- }
- }
- while (!st.empty()) st.pop();
- sum = 0;
- for (int i=1; i<=n; i++) {
- dodaj(p[i], p[i] == mx);
- if (p[i] == mx) break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement