Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll,pair<ll,ll> >pk;
- #define sf(a) scanf("%d",&a)
- #define pf(a) printf("%d\n",a)
- #define mp make_pair
- #define pb push_back
- //#define pop pop_back
- #define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
- #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
- #define mod 1000000007;
- int main()
- {
- fastread();
- ll n,k,i,sum=0,m;
- cin>>n>>k;
- vector<pk>v;
- ll ara[n+1],j;
- for(i=0; i<n; i++)
- cin>>ara[i];
- for(i=0; i<n; i++)
- {
- cin>>m;
- v.pb(mp(ara[i],mp(m,i)));
- }
- sort(v.begin(),v.end());
- priority_queue<ll,vector<ll>,greater<int>>pq;
- // priority_queue<ll>pq;
- for(i=0,j=0; i<n; i++,j++)
- {
- if(j<=k)
- {
- sum+=v[i].second.first;
- pq.push(v[i].second.first);
- }
- else
- {
- sum+=v[i].second.first-pq.top();
- pq.pop();
- pq.push(v[i].second.first);
- }
- ara[v[i].second.second]=sum;
- }
- for(i=0; i<n; i++)
- cout<<ara[i]<<" ";
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement