[伯俊/BOJ]12788第2回IUPCは順調に開催できますか?[Silver 4]

1422 ワード

  • 第2回IUPCは順調に開催できますか?
  • 質問元: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;
    }