문제출처 : https://www.acmicpc.net/problem/12788
정렬만해주면 진짜 쉽게 풀리는 문제이다.
code
#include <stdio.h> void QuickSort(int* arr, int start, int end) { if (start >= end) return; int piv = start, left = start + 1, right = end, temp; while (left < right) { while (left <= end && arr[left] >= arr[piv]) left++; while (right > start && arr[right] <= arr[piv]) right--; if (left > right) { temp = arr[right]; arr[right] = arr[piv]; arr[piv] = temp; } else { temp = arr[right]; arr[right] = arr[left]; arr[left] = temp; } } QuickSort(arr, start, right - 1); QuickSort(arr, right + 1, end); } int main() { int N, M, K, A[1000] = { 0 }, cnt = 0, sum = 0; scanf("%d", &N); scanf("%d %d", &M, &K); for (int i = 0; i < N; i++) scanf("%d", &A[i]); int people = M * K; QuickSort(A, 0, N - 1); for (int i = 0; i < N; i++) { if (sum < people) { sum += A[i]; cnt++; } else break; } if (sum >= people) printf("%d", cnt); else printf("STRESS"); return 0; }