Advertisement
Kevin_Zhang

Untitled

Nov 20th, 2021
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. #define pb emplace_back
  5. #define AI(i) begin(i), end(i)
  6. template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
  7. template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
  8. #ifdef KEV
  9. #define DE(args...) kout("[ " + string(#args) + " ]", args)
  10. void kout() { cerr << endl; }
  11. template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
  12. template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
  13. #else
  14. #define DE(...) 0
  15. #define debug(...) 0
  16. #endif
  17. const int MAX_N = 500010;
  18.  
  19. int N;
  20. // by strong
  21. // I cannot fight during [i, i+r[i]) days
  22. pair<int,int> sr[MAX_N];
  23.  
  24. ll res[MAX_N];
  25. vector<int> id[MAX_N];
  26.  
  27. ll sum;
  28. int req, pt, cur;
  29.  
  30. bool vis[MAX_N];
  31.  
  32. void upd() {
  33.     while (cur < req) {
  34.         if (!vis[pt]) {
  35.             sum += sr[pt].first;
  36.             ++cur;
  37.         }
  38.         ++pt;
  39.     }
  40. }
  41. void del(int id) {
  42.     assert(vis[id] == false);
  43.     vis[id] = true;
  44.     if (id < pt) {
  45.         --cur;
  46.         sum -= sr[id].first;
  47.     }
  48. }
  49.  
  50.  
  51. int32_t main() {
  52.     ios_base::sync_with_stdio(0), cin.tie(0);
  53.     cin >> N;
  54.     for (int i = 0;i < N;++i) cin >> sr[i].first;
  55.     for (int i = 0;i < N;++i) cin >> sr[i].second;
  56.     sort(sr, sr + N);
  57.     for (int i = 0;i < N;++i)
  58.         id[ sr[i].second ].pb(i);
  59.  
  60.     // I want to take away people who is strong
  61.     // aka who has bigger id
  62.     priority_queue<int> pq;
  63.     // I want to solve the i-th day's best
  64.     // now all soldier who rest less then i days, can get vaccinated
  65.     for (int i = 1;i <= N;++i) {
  66.         for (int j : id[i-1])
  67.             pq.push(j);
  68.         if (pq.size()) {
  69.             int x = pq.top(); pq.pop();
  70.             del(x);
  71.         } else {
  72.             ++req;
  73.         }
  74.         upd();
  75.         res[i] = sum;
  76.     }
  77.  
  78.     ll alls = 0;
  79.     for (int i = 0;i < N;++i) alls += sr[i].first;
  80.     for (int i = 1;i <= N;++i)
  81.         cout << alls - res[i] << " \n"[i==N];
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement