SHARE
TWEET

Untitled

a guest Feb 24th, 2020 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios::sync_with_stdio(false);
  8.     cin.tie(0);
  9.     cout.tie(0);
  10.     freopen("input.txt","r",stdin);
  11.     freopen("output.txt","w",stdout);
  12.     int n,k;
  13.     cin>>n>>k;
  14.     vector<int> v(n);
  15.     for(int i=0;i<n;i++)
  16.     {
  17.         cin>>v[i];
  18.     }
  19.     sort(v.rbegin(),v.rend());
  20.     int pointer=0;
  21.     int AmountLeft;
  22.     long long ans=0;
  23.     while(pointer<n)
  24.     {
  25.         ans+=2*v[pointer];
  26.         ans+=2*min((int)v.size()-pointer,k);
  27.         pointer+=min((int)v.size()-pointer,k);
  28.         //cout<<ans<<"\n";
  29.     }
  30.     cout<<ans;
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top