Advertisement
yuhung94

E

Nov 5th, 2022
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #pragma GCC optimzize("Ofast,no-stack-protector")
  2. #include<bits/stdc++.h>
  3. #define int long long
  4. #define quick ios::sync_with_stdio(0);cin.tie(0);
  5. #define rep(x,a,b) for(int x=a;x<=b;x++)
  6. #define repd(x,a,b) for(int x=a;x>=b;x--)
  7. #define lowbit(x) (x&-x)
  8. #define sz(x) (int)(x.size())
  9. #define F first
  10. #define S second
  11. #define all(x) x.begin(),x.end()
  12. #define mp make_pair
  13. #define eb emplace_back
  14. using namespace std;
  15. typedef pair<int,int> pii;
  16. void debug(){
  17.     cout<<"\n";
  18. }
  19. template <class T,class ... U >
  20. void debug(T a, U ... b){
  21.     cout<<a<<" ",debug(b...);
  22. }
  23. const int N=3e5+7;
  24. const int INF=1e18;
  25. int s[N];
  26. int w[N];
  27. int pos[N];
  28. signed main(){
  29.     quick
  30.     priority_queue<pii,vector<pii>> pq;
  31.     int n;
  32.     cin>>n;
  33.     rep(i,1,n) cin>>s[i];
  34.     rep(i,1,n) cin>>w[i];
  35.     set<int> st;
  36.     rep(i,1,n){
  37.         pq.push(mp(s[i],n-w[i]));
  38.         st.insert(i);
  39.     }
  40.     priority_queue<int,vector<int>,greater<int> > fail;
  41.     priority_queue<int> pq2;
  42.     int ok=0;
  43.     int sum=0;
  44.     while(pq.size()){
  45.         auto it=st.upper_bound(pq.top().S);
  46.         if(it==st.begin()){
  47.             pq2.push(pq.top().F);
  48.         }
  49.         else{
  50.             int k=*prev(it);
  51.             pos[k]=pq.top().F;
  52.             st.erase(prev(it));
  53.         }
  54.         pq.pop();
  55.     }
  56.     rep(i,1,n) sum+=pos[i];
  57.     vector<int> ans;
  58.     rep(i,1,n){
  59.         ans.eb(sum);
  60.         pq2.push(pos[i]);
  61.         sum-=pos[i];
  62.         if(pq2.size()){
  63.             fail.push(pq2.top());
  64.             sum+=pq2.top();
  65.             pq2.pop();
  66.         }
  67.     }
  68.     reverse(all(ans));
  69.     rep(i,0,n-1){
  70.         cout<<ans[i]<<" \n"[i==n-1];
  71.     }
  72.     return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement