Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int N;
- cin >> N;
- vector<int> a(N), b(N);
- for (auto &x : a) cin >> x;
- for (auto &x : b) cin >> x;
- for (int i = 1; i < N; i++) a[i] += a[i-1];
- set<pair<int, int> >resp; int soma = 0;
- for (int i = 0; i < N; i++)
- {
- if (a[i] < b[i]) continue;
- if (soma + b[i] <= a[i]) {resp.emplace(b[i], i); soma += b[i];}
- else
- {
- soma += b[i]; resp.emplace(b[i], i);
- soma -= resp.rbegin()->first; resp.erase((--resp.end()));
- }
- }
- vector<int> ans;
- for (auto [x, id] : resp) ans.push_back(id);
- sort(ans.begin(), ans.end());
- cout << ans.size() << '\n';
- for (auto x : ans) cout << x+1 << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement