Advertisement
ThegeekKnight16

Warehouse Store

May 3rd, 2023
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(NULL);
  8.     int N;
  9.     cin >> N;
  10.     vector<int> a(N), b(N);
  11.     for (auto &x : a) cin >> x;
  12.     for (auto &x : b) cin >> x;
  13.     for (int i = 1; i < N; i++) a[i] += a[i-1];
  14.  
  15.     set<pair<int, int> >resp; int soma = 0;
  16.     for (int i = 0; i < N; i++)
  17.     {
  18.         if (a[i] < b[i]) continue;
  19.         if (soma + b[i] <= a[i]) {resp.emplace(b[i], i); soma += b[i];}
  20.         else
  21.         {
  22.             soma += b[i]; resp.emplace(b[i], i);
  23.             soma -= resp.rbegin()->first; resp.erase((--resp.end()));
  24.         }
  25.     }
  26.  
  27.     vector<int> ans;
  28.     for (auto [x, id] : resp) ans.push_back(id);
  29.     sort(ans.begin(), ans.end());
  30.     cout << ans.size() << '\n';
  31.     for (auto x : ans) cout << x+1 << " ";
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement