#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, char** argv)
{
int n,m,k;
scanf("%d %d %d", &n, &m, &k);
vector<int> rails(n);
sort(rails.begin(), rails.end());
for(int i=0; i<n; i++){
scanf("%d", &rails[i]);
}
sort(rails.begin(), rails.end());
int ans = 3000; // 문제 범위에서 최대 무게는 2500
do{
int load=0, idx=0;
for(int i=0; i<k; i++){
int r=m;
while(true){
r -= rails[idx];
if(r<0) break;
load += rails[idx++];
idx %= n;
}
}
ans = min(ans, load);
}while(next_permutation(rails.begin(), rails.end()));
cout << ans << endl;
return 0;
}
Leave a comment