Maximising Swiggy Genie Pick Up Drop Off Revenues
Autocomplete Ready
1 > #include ...
ALL
* Complete the 'maximiseReven
*The function is expected to
The function accepts follow 1. LONG INTEGER ARRAY picks
A Swiggy Delivery Partner knows the pick-up and drop-off locations of parcels requested by customers using Swiggy's Genie Service. All the locations are in km from the starting point. The starting point is at 0 km.
O
1
For each km to transport a parcel, the Delivery Partner charges 1 unit of money per parcel. Some Genie customers are even willing to pay an extra tip if the Delivery Partner is ready to pick and drop off their parcel. At any point of time, the Delivery Partner can only deliver one parcel. Determine the maximum amount the Delivery Partner can earn.
26
28
29
*2. LONG INTEGER ARRAY drop
3. INTEGER ARRAY tip
Long maximiseRevenue (int pickup
drop_count, long drop, int tip
Example
pickup=[0, 2, 9, 10, 11, 12]
31
drop=[5, 9, 11, 11, 14, 17]
32
tip=[1, 2, 3, 2, 2, 1]
33 1
34
35> int main()...
2
3
The way to earn the most money is by accepting parcels at indices 1, 2 and 5.
The amount paid by the customer at index 1:9-2+2=9
•The amount paid by the customer at index 2: 11-9+3=5
•The amount paid by the customer at index 5: 17-12+1=6 • The total amount paid by the customers is 9+5+6=20
Therefore, the return value is 20.
Function Description
Complete the function maximiseRevenue in the editor below. The function must return an integer
denoting the maximum amount that can be earned by the Delivery Partner.
maximiseRevenue has the following parameter(s):
ALL
pickup/pickup[0]...pickup[n-1]: an array of n integers that denote the pickup location of the potential parcels
drop/drop[0]...drop[n-1]): an array of n integers that denote the drop-off locations of the potential
parcels
tip tip[0]...tip[n-1]: an array of n integers that denote the tips offered by each customer if their parcel is
accepted for pick up and drop off
1
Constraints
2
.0<|pickup. drop. Itip s 104
Os pickup, drops 1012
pickup, drop
. Os tips 105
Input Format For Custom Testing
The first line contains an integer, n, the number of elements in pickup. Each line of the n subsequent lines (where Os/
Sample Case 0
Sample Input For Custom Testing
Autocomplete Ready
1> #include ...
55m left
Function
STDIN
→ pickup[] size n = 2 pickup[] = [1, 4]
drop[] size n = 2
drop[]=[5, 6]
tip[] size n = 2
+ tip[] = [ 2, 5]
Sample Output
7
Explanation
There are two parcels, and locations are overlapping so only one of them can be accepted. If parcel 1 is picked, the amount made is 5-1+2 = 6 If parcel 2 is picked, the amount made is 6-4+5=7
It is best to pick parcel 2 and earn 7.
Sample Case 1
Sample Input For Custom Testing
STDIN
3
Function
→ pickup[] size n = 3
pickup[] = [0, 4, 5]