-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-SmartPhone.java
More file actions
84 lines (62 loc) · 1.78 KB
/
4-SmartPhone.java
File metadata and controls
84 lines (62 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Question
/*
You are developing a smartphone app. You have a list of potential customers for your app. Each customer has a budget and will buy the app at your declared price if and only if the price is less than or equal to the customer's budget.
You want to fix a price so that the revenue you earn from the app is maximized. Find this maximum possible revenue.
For instance, suppose you have 4 potential customers and their budgets are 30, 20, 53 and 14. In this case, the maximum revenue you can get is 60 .
Input format
Line 1 : N, the total number of potential customers.
Lines 2 to N+1: Each line has the budget of a potential customer.
Output format
The output consists of a single integer, the maximum possible revenue you can earn from selling your app.
Sample Input 1
4
30
20
53
14
Sample Output 1
60
Sample Input 2
5
40
3
65
33
21
Sample Output 2
99
Test data
Each customers' budget is between 1 and 108, inclusive.
Subtask 1 (30 marks) : 1 ≤ N ≤ 5000.
Subtask 2 (70 marks) : 1 ≤ N ≤ 5×105.
Live evaluation data
There are 15 test inputs on the server during the exam. The grouping into subtasks is as follows.
• Subtask 1: Test inputs 0,…,5
• Subtask 2: Test inputs 6,…,14
*/
//Solution
import java.util.*;
import java.lang.*;
import java.io.*;
class Sol
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan=new Scanner(System.in);
int noOfCustomers=scan.nextInt();
long maxRev=0;
long[] budget=new long[noOfCustomers];
for(int i=0; i<noOfCustomers; i++){
budget[i]=scan.nextInt();
}
Arrays.sort(budget);
for(int i=0; i<noOfCustomers; i++){
// System.out.println(budget[i]);
long a=budget[i]*(noOfCustomers-i);
if(a>maxRev){
maxRev=a;
}
}
System.out.println(maxRev);
}
}