Advertisement
Guest User

Hiring

a guest
Jun 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long llint;
  6.  
  7. const int MAXN = 500005;
  8.  
  9. llint n, w, sum;
  10. llint s[MAXN], q[MAXN], p[MAXN], cnt[MAXN], val[MAXN];
  11. priority_queue < pair <llint, int> > st;
  12.  
  13. bool cmp (int x, int y) {
  14. return q[x] * s[y] > q[y] * s[x];
  15. }
  16.  
  17. bool cmp2 (int x, int y) {
  18. if (cnt[x] != cnt[y]) return cnt[x] > cnt[y];
  19. return val[x] * s[x] * q[y] < val[y] * s[y] * q[x];
  20. }
  21.  
  22. void dodaj (int x, bool flg) {
  23. st.push(make_pair(q[x], x));
  24. sum += q[x];
  25. while (sum * s[x] > w * q[x]) {
  26. sum -= st.top().first;
  27. st.pop();
  28. }
  29. cnt[x] = st.size();
  30. val[x] = sum;
  31. if (flg) {
  32. cout << cnt[x] << endl;
  33. while (!st.empty()) {
  34. cout << st.top().second << endl;
  35. st.pop();
  36. }
  37. }
  38. }
  39.  
  40. int main () {
  41. ios_base::sync_with_stdio(false);
  42. cin.tie(0);
  43. cin >> n >> w;
  44. for (int i=1; i<=n; i++) {
  45. cin >> s[i] >> q[i];
  46. p[i] = i;
  47. }
  48. sort(p + 1, p + 1 + n, cmp);
  49. int mx = p[1];
  50. for (int i=1; i<=n; i++) {
  51. dodaj(p[i], 0);
  52. //cout << "bla " << p[i] << " " << cnt[p[i]] << endl;
  53. if (cmp2(p[i], mx)) {
  54. mx = p[i];
  55. }
  56. }
  57. while (!st.empty()) st.pop();
  58. sum = 0;
  59. for (int i=1; i<=n; i++) {
  60. dodaj(p[i], p[i] == mx);
  61. if (p[i] == mx) break;
  62. }
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement