SmartPhone

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.

@mukul8
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

@gulshan_yadav
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;
temp=T;
vector v;
vector res;
while(T–)
{
long long int num;
cin >> num;
v.push_back(num);
}

sort(v.begin(),v.end());

for(int i=0;i<v.size();i++)
{
    long long int r=0;
    r=v.at(i);
    r*=(temp-i);
    res.push_back(r);
}
sort(res.begin(),res.end());
temp=res.size();
cout << res.at(temp-1); 

}

what is wrong with my code
#include
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=0,sum=0,y=0;
cin>>n;
int a[n]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
int x=a[0];
while(x<=a[n-1]){
for(int i=0;i<n;i++){
if(x>a[i])
sum++;
else
break;
}int rev=0;
rev=x*(n-sum);
sum=0;

if(y<rev)
y=rev;
x++;}
cout<<y;
}

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) .