Friday, August 26, 2016

UVA 11900 - Boiled Eggs solution

problem link-click here

nothing to say about this problem. just read the given statement very carefully and solve it. it's fully implemented based problem along with super easy.

an accepted code is given below:

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,p,q,n,i=1;

    scanf("%d",&t);

    while(t--)
    {
        int arr[100]={0},j=0;
        scanf("%d%d%d",&n,&p,&q);

        while(j<n)
        {
            scanf("%d",&arr[j]);
            j++;
        }

        sort(arr,arr+n);

        int sum=0,c=0;

       for(int k=0;k<n;k++)
       {
           sum=sum+arr[k];

           if(sum<=q)
           {
               c++;
           }
           else
           {
               break;
           }

           if(c>=p)
           {
               break;
           }
       }

        printf("Case %d: %d\n",i,c);

        i++;
    }

    return 0;
}

No comments:

Post a Comment