structyhzhyhm { int v, w, id; booloperator < (const yhzhyhm &x) const { return (v > x.v) || ((v == x.v) && (id < x.id)); } }yh[N];
priority_queue<int, vector<int>, greater<int> >q;
signedmain() { int i, x, n = read(); for (i = 1; i <= n; ++ i) yh[i].v = read(), yh[i].w = read(), yh[i].id = i; x = yh[1].v; sort(yh + 1, yh + 1 + n); cout << "------------------------\n"; for (i = 1; i <= n; ++ i) cout << yh[i].v << ' ' << yh[i].w << '\n'; for (i = 1; i <= n; ++ i) { if (yh[i].id == 1) break; q.push(yh[i].w - yh[i].v + 1); }
int res = i, rnk = i, pos = i, ret = x, pd = 1; /* res is answer rnk is now_pai_ming pos is now_wei_zhi ret is now_shengyu pd is now_tag */ cout << "rnk--->" << rnk << '\n'; while (! q.empty() && pd == 1) { pd = 0, x = q.top(); q.pop(); cout << "x-->" << x << '\n'; if (ret >= x) ret -= x, pd = 1; if (! pd) break; int num = 0; for (i = pos + 1; i <= n; ++ i) { if (yh[i].v <= ret) break; ++ num; q.push(yh[i].w - yh[i].v + 1); } pos = i - 1, rnk = rnk - 1 + num;