Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define pb emplace_back
- #define AI(i) begin(i), end(i)
- template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
- template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
- #ifdef KEV
- #define DE(args...) kout("[ " + string(#args) + " ]", args)
- void kout() { cerr << endl; }
- template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
- template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
- #else
- #define DE(...) 0
- #define debug(...) 0
- #endif
- const int MAX_N = 500010;
- int N;
- // by strong
- // I cannot fight during [i, i+r[i]) days
- pair<int,int> sr[MAX_N];
- ll res[MAX_N];
- vector<int> id[MAX_N];
- ll sum;
- int req, pt, cur;
- bool vis[MAX_N];
- void upd() {
- while (cur < req) {
- if (!vis[pt]) {
- sum += sr[pt].first;
- ++cur;
- }
- ++pt;
- }
- }
- void del(int id) {
- assert(vis[id] == false);
- vis[id] = true;
- if (id < pt) {
- --cur;
- sum -= sr[id].first;
- }
- }
- int32_t main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- cin >> N;
- for (int i = 0;i < N;++i) cin >> sr[i].first;
- for (int i = 0;i < N;++i) cin >> sr[i].second;
- sort(sr, sr + N);
- for (int i = 0;i < N;++i)
- id[ sr[i].second ].pb(i);
- // I want to take away people who is strong
- // aka who has bigger id
- priority_queue<int> pq;
- // I want to solve the i-th day's best
- // now all soldier who rest less then i days, can get vaccinated
- for (int i = 1;i <= N;++i) {
- for (int j : id[i-1])
- pq.push(j);
- if (pq.size()) {
- int x = pq.top(); pq.pop();
- del(x);
- } else {
- ++req;
- }
- upd();
- res[i] = sum;
- }
- ll alls = 0;
- for (int i = 0;i < N;++i) alls += sr[i].first;
- for (int i = 1;i <= N;++i)
- cout << alls - res[i] << " \n"[i==N];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement