Chef and Price Control||codechef||beginner solution ||programming info

Chef and Price Control

Chef has  items in his shop (numbered 1 through ); for each valid i, the price of the i-th item is Pi. Since Chef has very loyal customers, all Nitems are guaranteed to be sold regardless of their price.

However, the government introduced a price ceiling , which means that for each item i such that its price should be reduced from ito .

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

  • 1T100
  • 1N10,000
  • 1Pi1,000 for each valid i
  • 1K1,000

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 10+2+3+4+5=24. Because of the price ceiling,  decreases from 10 to 4 and  decreases from 5 to 4. The revenue afterwards is 4+2+3+4+4=17 and the lost revenue is 2417=7.

Test Case 2: The initial revenue is 1+2+3+4+5+6+7=28. For each valid i, 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 10+9+8+7+6=40. Since  for each valid i, the prices of all items decrease to 5. The revenue afterwards is 55=25 and the lost revenue is 4025=15.

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));
	
		}
}

Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support