Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimzize("Ofast,no-stack-protector")
- #include<bits/stdc++.h>
- #define int long long
- #define quick ios::sync_with_stdio(0);cin.tie(0);
- #define rep(x,a,b) for(int x=a;x<=b;x++)
- #define repd(x,a,b) for(int x=a;x>=b;x--)
- #define lowbit(x) (x&-x)
- #define sz(x) (int)(x.size())
- #define F first
- #define S second
- #define all(x) x.begin(),x.end()
- #define mp make_pair
- #define eb emplace_back
- using namespace std;
- typedef pair<int,int> pii;
- void debug(){
- cout<<"\n";
- }
- template <class T,class ... U >
- void debug(T a, U ... b){
- cout<<a<<" ",debug(b...);
- }
- const int N=3e5+7;
- const int INF=1e18;
- int s[N];
- int w[N];
- int pos[N];
- signed main(){
- quick
- priority_queue<pii,vector<pii>> pq;
- int n;
- cin>>n;
- rep(i,1,n) cin>>s[i];
- rep(i,1,n) cin>>w[i];
- set<int> st;
- rep(i,1,n){
- pq.push(mp(s[i],n-w[i]));
- st.insert(i);
- }
- priority_queue<int,vector<int>,greater<int> > fail;
- priority_queue<int> pq2;
- int ok=0;
- int sum=0;
- while(pq.size()){
- auto it=st.upper_bound(pq.top().S);
- if(it==st.begin()){
- pq2.push(pq.top().F);
- }
- else{
- int k=*prev(it);
- pos[k]=pq.top().F;
- st.erase(prev(it));
- }
- pq.pop();
- }
- rep(i,1,n) sum+=pos[i];
- vector<int> ans;
- rep(i,1,n){
- ans.eb(sum);
- pq2.push(pos[i]);
- sum-=pos[i];
- if(pq2.size()){
- fail.push(pq2.top());
- sum+=pq2.top();
- pq2.pop();
- }
- }
- reverse(all(ans));
- rep(i,0,n-1){
- cout<<ans[i]<<" \n"[i==n-1];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement