Electronics Shop

A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given price lists for keyboards and USB drives and a budget, find the cost to buy them. If it is not possible to buy both items, return

.

Example

The person can buy a , or a . Choose the latter as the more expensive option and return

.

Function Description

Complete the getMoneySpent function in the editor below.

getMoneySpent has the following parameter(s):

int keyboards[n]: the keyboard prices
int drives[m]: the drive prices
int b: the budget

Returns

int: the maximum that can be spent, or 

if it is not possible to buy both items

Input Format

The first line contains three space-separated integers
, , and , the budget, the number of keyboard models and the number of USB drive models.
The second line contains space-separated integers , the prices of each keyboard model.
The third line contains space-separated integers

, the prices of the USB drives.

Constraints

The price of each item is in the inclusive range

.

Sample Input 0

10 2 3
3 1
5 2 8

Sample Output 0

9

Sample Input 1

5 1 1
4
5

Sample Output 1

-1

first sort both the vectors and then run two loops

Reference code

int getMoneySpent(vector<int> keyboards, vector<int> drives, int b) {
    int n=keyboards.size();
    int m=drives.size();
    sort(keyboards.begin(),keyboards.end());
    sort(drives.begin(),drives.end());
    int ans=INT_MIN;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int temp=keyboards[i]+drives[j];
            if(temp<=b){
                ans=max(ans,temp);
            }
            else break;
        }
    }
    if(ans==INT_MIN)return -1;
    return ans;
}

thanks but it would be good if u provide cb ide soln as direct text ommits >> into lt etc

this is the code

if your doubt is resolved
don’t forgot to mark it as resolved

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.