본문 바로가기
알고리즘/그리디 알고리즘

12018 yonsei toto

by tryotto 2019. 6. 28.
#include <stdio.h>
#include <algorithm>
using namespace std;
int arr[105] = { 0 };
bool desc(int a, int b) {
return a > b;
}
int main() {
int t, point, idx = 0;
scanf("%d %d", &t, &point);
while (t--) {
int all, can;
scanf("%d %d", &all, &can);
int temp[105] = { 0 };
for (int i = 0; i < all; i++) {
scanf("%d", &temp[i]);
}
if (all < can) {
arr[idx++] = 1;
continue;
}
sort(temp, temp + all, desc);
arr[idx++] = temp[can - 1];
}
sort(arr, arr + idx);
int total = 0,ans=0;
for (int i = 0; i < idx; i++) {
if (total + arr[ans] <= point) {
total += arr[ans++];
}
else {
break;
}
}
printf("%d", ans);
}


'알고리즘 > 그리디 알고리즘' 카테고리의 다른 글

2828 사과담기 게임  (0) 2019.06.28
2816 디지털 티비  (0) 2019.06.28
1439 뒤집기  (0) 2019.06.28
1507 궁금한 민호  (0) 2019.06.27
1343 폴리노미오  (0) 2019.06.27