I am unable to understand the problem…How does the revenue is calculated.Plz explain

You need to find the price for your app such that it will maximize your revenue, like 30 20 53 14 now if you set your price for the app to be 30 2 customers will give you revenue of 60 which is maximized revenue, you can also have 20 as your app price still you would reach 60 but if you would have 14 then it will be 56 revenue which is less than maximum. You need to find the price which will maximize the revenue

The problem still shows WA.I am taking long long for the answer.

see mukul
there are 4 customers who have their budget let say 20 14 30 53.
you have to set the price such that your profit will maximize.
so what you can do is that suppose you set the price : 14 so 4 customer can buy that app
and you profit is 14* 4=42:
and if you set the price 20 : now only three costumer can buy that app and you profit is 20*3=60:
and so on .

1 Like

I have done the problem with the same approach but i think that there is some error due to the constraints of the problem.Any ideas how to tackle it?

When 30 price is set then why only 2 customers will give revenue. Can you explain it?

When you sort the price , it now becomes like this 14 20 30 53.Now,when you set 30 as the price only people having budget 30 and 53 can afford it.So ,only these 2 people will give revenue

here you have to check that among the given prices which prices do you choose so that by setting that price as the cost price of the item, how many others budget is greater than or equal to the price the we set.
so the question is what should we set the price so that the revenue will comes out to be maximum.

because if we set price to 30 then only two people can buy it
the one with the budget of 50 and the other with budget of 30 itself.

could you please share your approach or paste the code here in discuss forum.

Here’s my code:
#include <bits/stdc++.h>

using namespace std;

int main()
int T,temp;
cin >> T;
vector v;
vector res;
long long int num;
cin >> num;


for(int i=0;i<v.size();i++)
    long long int r=0;;
cout <<; 


what is wrong with my code
using namespace std;
int main()
int n=0,sum=0,y=0;
int a[n]={0};
for(int i=0;i<n;i++)
int x=a[0];
for(int i=0;i<n;i++){
}int rev=0;


format your code

You need to make revenue maximum, You need to choose a price which that will give you the maximum benefit . which is basically - price * ( number of potential customers ) . I will give the procedure without revealing the code
INPUT - 40 3 65 33 21
First Step - 3 21 33 40 65
Third Step -
3 * 5 = 15 ;
21 * 4 = 84 ;
33 * 3 = 99 ;
40 * 2 = 80 ;
65 * 1 = 65 ;
OUTPUT - maximum revenue = 99 ;

For the Constraints ( as you mentioned ) = 10 ^ 8 * 5 (max case) ;
you can use unsigned long long (only positive int) (size 128 bit) which should be more than enough (long long is also good enough) .