Sita shortlists 4 gifts priced at r1, r2, r3 and r4 respectively. She wants to buy 3 of these gifts such that it doesn't exceed her budget of x.
Input and Output Format:
Input consists of 5 integers that correspond to r1, r2, r3, r4 and x. Output consists of 2 integers. The first integer corresponds to the minimal amount she would spend for buying 3 gifts. The second integer corresponds to the maximal amount she would spend for buying 3 gifts, staying within the budget.
Sample Input
20 30 10 25 80
Sample Output
55 75
#include<stdio.h>
int main()
{
int x,a[4],i,j,n,temp,big,small,sum=0;
// scanf("%d",&r1);
// scanf("%d",&r2);
// scanf("%d",&r3);
// scanf("%d",&r4);
// scanf("%d",&x);
big = 0;
n=4;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&x);
for(i=0;i<n;i++)
{
for(j=i;j<(n);j++)
{
if(a[i]>a[j]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
sum+=a[i];
}
//sum = a[0]+a[]
small = sum-a[3];
if((sum-a[0])<=x)
big = sum-a[0];
else if((sum-a[1])<=x)
big = sum-a[1];
else if((sum-a[2])<=x)
big = sum-a[2];
else
big = small;
if(small<=x){
printf("%d",small);
}
if(big == small){
return 0;
}
if(big<=x){
printf("\n%d",big);
}
return 0;
}