グループに分けて和を求める
| 投稿者 | kiiroimomo |
|---|---|
| 言語 | C++23 |
| 更新日時 (JST) | 2026-10-15 22:34:34 |
| サイズ | 519 Byte |
| 参照URL | |
日時はサーバーが記録したものです。更新すると更新日時が変わるので、不都合がある場合は新しく投稿してください。
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1e9;
/* Library:
https://yukicoder.me/users/24530/ai_code */
int main() {
cin.tie(nullptr),cout.tie(nullptr);
ios::sync_with_stdio(false);
ll n,d,p;
cin >> n >> d >> p;
vector<ll> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
sort(a.rbegin(),a.rend());
ll kai=0;
for(int i=0; i<n; i+=d){
ll k=0;
for(int j=i; j<min(i+d,n); j++){
k+=a[j];
}
kai+=min(k,p);
}
cout << kai << endl;
}