Skip to content

Instantly share code, notes, and snippets.

@shubham1710
Created December 13, 2019 13:25
Show Gist options
  • Save shubham1710/077fdd7b86de04c0f6c2b7e9ec57924e to your computer and use it in GitHub Desktop.
Save shubham1710/077fdd7b86de04c0f6c2b7e9ec57924e to your computer and use it in GitHub Desktop.
Ggg
int main() {
int n, k; cin >> n >> k;
vector<int> v(n);
for(int i = 0; i < n; ++i)
cin >> v[i];
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
int tot = 0;
for(int i = 0; i < n; ++i) {
tot += ((i / k) + 1) * v[i];
}
cout << tot << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment