Advertisement
Fahim_7861

B. Knights of a Polygonal Table Codeforce

Jun 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<ll,pair<ll,ll> >pk;
  5. #define sf(a) scanf("%d",&a)
  6. #define pf(a) printf("%d\n",a)
  7. #define mp make_pair
  8. #define pb push_back
  9. //#define pop pop_back
  10. #define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
  11. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  12. #define mod 1000000007;
  13.  
  14. int main()
  15. {
  16.    fastread();
  17.  
  18.    ll n,k,i,sum=0,m;
  19.  
  20.    cin>>n>>k;
  21.  
  22.    vector<pk>v;
  23.  
  24.    ll ara[n+1],j;
  25.  
  26.    for(i=0; i<n; i++)
  27.     cin>>ara[i];
  28.  
  29.    for(i=0; i<n; i++)
  30.    {
  31.        cin>>m;
  32.  
  33.        v.pb(mp(ara[i],mp(m,i)));
  34.    }
  35.  
  36.    sort(v.begin(),v.end());
  37.  
  38.    priority_queue<ll,vector<ll>,greater<int>>pq;
  39.    // priority_queue<ll>pq;
  40.  
  41.    for(i=0,j=0; i<n; i++,j++)
  42.    {
  43.        if(j<=k)
  44.        {
  45.            sum+=v[i].second.first;
  46.  
  47.            pq.push(v[i].second.first);
  48.        }
  49.        else
  50.        {
  51.  
  52.                sum+=v[i].second.first-pq.top();
  53.                pq.pop();
  54.                pq.push(v[i].second.first);
  55.  
  56.  
  57.        }
  58.        ara[v[i].second.second]=sum;
  59.    }
  60.  
  61.    for(i=0; i<n; i++)
  62.     cout<<ara[i]<<" ";
  63.  
  64.    cout<<endl;
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement