Chef and Price Control
Chef has items in his shop (numbered through ); for each valid , the price of the -th item is . Since Chef has very loyal customers, all items are guaranteed to be sold regardless of their price.
However, the government introduced a price ceiling , which means that for each item such that its price should be reduced from to .
Chef's revenue is the sum of prices of all the items he sells. Find the amount of revenue which Chef loses because of this price ceiling.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains two space-separated integers and .
- The second line contains space-separated integers
Output
For each test case, print a single line containing one integer ― the amount of lost revenue.
Constraints
- for each valid
Subtasks
Subtask #1 (100 points): original constraints
Example Input
3
5 4
10 2 3 4 5
7 15
1 2 3 4 5 6 7
5 5
10 9 8 7 6
Example Output
7
0
15
Explanation
Test Case 1: The initial revenue is . Because of the price ceiling, decreases from to and decreases from to . The revenue afterwards is and the lost revenue is .
Test Case 2: The initial revenue is . For each valid , , so there are no changes, the revenue after introduction of the price ceiling is the same and there is zero lost revenue.
Test Case 3: The initial revenue is . Since for each valid , the prices of all items decrease to . The revenue afterwards is and the lost revenue is .
SOLUTION USING C LANGUAGE:-
#include<stdio.h>
int main()
{
int t,i;
scanf("%d",&t);
int n,k,p[10000];
while(t--)
{
int s=0,l=0;
scanf("%d %d",&n,&k);
for(i=0;i<n;i++)
{
scanf("%d\t",&p[i]);
}
for(i=0;i<n;i++)
{
s=s+p[i];
}
for(i=0;i<n;i++)
{
if(p[i]>k)
p[i]=k;
}
for(i=0;i<n;i++)
{
l=l+p[i];
}
printf("%d\n",(s-l));
}
}







No comments:
Post a Comment