if you want to remove an article from website contact us from top.

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

Category :

### Mohammed

Guys, does anyone know the answer?

get 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 . from screen.

## Electronics Shop

Determine the most expensive Keyboard and USB drive combination one can purchase within her budget.

Electronics Shop Problem Submissions Leaderboard Editorial

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

Explanation 0

Buy the keyboard and the USB drive for a total cost of .

Sample Input 1

5 1 1 4 5

Sample Output 1

-1

Explanation 1

There is no way to buy one keyboard and one USB drive because , so return .

vector

Change Theme C++ 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 fout.close(); return 0; }

split_string(string input_string) {

string::iterator new_end = unique

(input_string.begin(), input_string.end(), []

(const char &x, const char &y) {

return x == y and x == ' ';

});

input_string.erase(new_end, input_string.end()

);

while (input_string[input_string.length() - 1]

== ' ') {

input_string.pop_back();

vector

}

splits;

char delimiter = ' ';

size_t i = 0;

size_t pos = input_string.find(delimiter);

while (pos != string::npos) {

splits.push_back(input_string.substr(i,

pos - i)); i = pos + 1;

pos = input_string.find(delimiter, i);

}

splits.push_back(input_string.substr(i, min

(pos, input_string.length()) - i + 1));

return splits; } Line: 99 Col: 1

स्रोत : www.hackerrank.com

## Electronics Shop

A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give …

## Electronics Shop

### Problem Statement :

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

Example b = 60

keyboards = [40, 50, 60]

drives = [5, 8,12]

The person can buy a 40 keyboards + 12 USB drives = 52, or a 50 keyboards + 8 USB drives = 58. Choose the latter as the more expensive option and return 58.

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 -1 if it is not possible to buy both items

Input Format

The first line contains three space-separated integers b, n, and m, the budget, the number of keyboard models and the number of USB drive models.

The second line contains n space-separated integers keyboard[i], the prices of each keyboard model.

The third line contains m space-separated integers drives, the prices of the USB drives.

Constraints 1 <= n,m <= 1000 1 <= b <= 10^6

The price of each item is in the inclusive range [1, 10^6].

### Solution :

Solution in C : python 3 : #!/bin/python3 import sys

s,n,m = input().strip().split(' ')

s,n,m = [int(s),int(n),int(m)]

a = [int(keyboards_temp) for keyboards_temp in input().strip().split(' ')]

b = [int(pendrives_temp) for pendrives_temp in input().strip().split(' ')]

ans = -1 for x in a: for y in b: if x + y <= s:

ans = max(ans, x + y)

print (ans) Java : import java.io.*; import java.util.*; import java.text.*; import java.math.*;

import java.util.regex.*;

public class Solution {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int s = in.nextInt();

int n = in.nextInt();

int m = in.nextInt();

int[] keyboards = new int[n];

for(int keyboards_i=0; keyboards_i < n; keyboards_i++){

keyboards[keyboards_i] = in.nextInt();

}

int[] pendrives = new int[m];

for(int pendrives_i=0; pendrives_i < m; pendrives_i++){

pendrives[pendrives_i] = in.nextInt();

for(int i=0;i

} int max=0;

for(int j=0;j

if(keyboards[i]+pendrives[j]<=s){

if(max

max=keyboards[i]+pendrives[j];

} } } }

System.out.println(max==0?-1:max);

#include

} } C++ :

using namespace std;

int ans=-1, a[1005], b[1005], i, n, m, s, j;

int main() {

scanf("%d%d%d", &s, &n, &m);

for(i=1; i<=n; ++i) scanf("%d", &a[i]);

for(i=1; i<=m; ++i) scanf("%d", &b[i]);

for(i=1; i<=n; ++i) for(j=1; j<=m; ++j)

if(a[i]+b[j]<=s) ans = max(a[i]+b[j], ans);

printf("%d\n", ans);

#include

return 0; } C :

#include #include #include #include #include #include

int main(){ int s; int n; int m,i,j,k,l;

scanf("%d %d %d",&s,&n,&m);

int *keyboards = malloc(sizeof(int) * n);

for(int keyboards_i = 0; keyboards_i < n; keyboards_i++){

scanf("%d",&keyboards[keyboards_i]);

}

int *pendrives = malloc(sizeof(int) * m);

for(int pendrives_i = 0; pendrives_i < m; pendrives_i++){

scanf("%d",&pendrives[pendrives_i]);

for(i=0;i

} k=-1;

for(j=0;j

{ if(keyboards[i]>=s) { continue; }

{

if(keyboards[i]+pendrives[j]<=s&&keyboards[i]+pendrives[j]>k)

{

k=keyboards[i]+pendrives[j];

} } } printf("%d",k); return 0; }

## View More Similar Problems

View More Similar Problems Square-Ten Tree

The square-ten tree decomposition of an array is defined as follows: The lowest () level of the square-ten tree consists of single array elements in their natural order. The level (starting from ) of the square-ten tree consists of subsequent array subsegments of length in their natural order. Thus, the level contains subsegments of length , the level contains subsegments of length , the

View Solution →

## Balanced Forest

Greg has a tree of nodes containing integer data. He wants to insert a node with some non-zero integer value somewhere into the tree. His goal is to be able to cut two edges and have the values of each of the three new trees sum to the same amount. This is called a balanced forest. Being frugal, the data value he inserts should be minimal. Determine the minimal amount that a new node can have to a

View Solution →

## Jenny's Subtrees

Jenny loves experimenting with trees. Her favorite tree has n nodes connected by n - 1 edges, and each edge is ` unit in length. She wants to cut a subtree (i.e., a connected part of the original tree) of radius r from this tree by performing the following two steps: 1. Choose a node, x , from the tree. 2. Cut a subtree consisting of all nodes which are not further than r units from node x .

स्रोत : hackerranksolution.in

## Electronics Shop

Hello coders, today we are going to solve Electronics Shop HackerRank Solution which is a Part of HackerRank Algorithm Series.

## Electronics Shop | HackerRank Solution

Hello coders, today we are going to solve Electronics Shop HackerRank Solution which is a Part of HackerRank Algorithm Series.

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

Exampleb = 60keyboards = [40, 50, 60]drivers = [5, 8, 12]

The person can buy a 40 keyboard + 12 USB drive = 52, or a 50 keyboard + 8 USB drive = 58. Choose the latter as the more expensive option and return 58.

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 -1 if it is not possible to buy both items

## Input Format

The first line contains three space-separated integers bn, and m, the budget, the number of keyboard models and the number of USB drive models.

The second line contains n space-separated integers keyboard[i], the prices of each keyboard model.

The third line contains m space-separated integers drives, the prices of the USB drives.

## Constraints

1 <= n, m < 10001 <= b <= 106

The price of each item is in the inclusive range [1, 106].

Sample Input 0

10 2 3 3 1 5 2 8

Sample Output 0

9

Explanation 0

Buy the 2nd keyboard and the 3rd USB drive for a total cost of 8 + 1 = 9.

Sample Input 1

5 1 1 4 5

Sample Output 1

-1

Explanation 1

There is no way to buy one keyboard and one USB drive because 4 + 5 > 5, so return -1.

## Solution – Electronics Shop

### C++

#include

using namespace std;

int ans=-1, a[1005], b[1005], i, n, m, s, j;

int main() {

scanf("%d%d%d", &s, &n, &m);

for(i=1; i<=n; ++i) scanf("%d", &a[i]);

for(i=1; i<=m; ++i) scanf("%d", &b[i]);

for(i=1; i<=n; ++i) for(j=1; j<=m; ++j)

if(a[i]+b[j]<=s) ans = max(a[i]+b[j], ans);

printf("%d\n", ans);

return 0; }

### Python

import sys

s,n,m = input().strip().split(' ')

s,n,m = [int(s),int(n),int(m)]

a = [int(keyboards_temp) for keyboards_temp in input().strip().split(' ')]

b = [int(pendrives_temp) for pendrives_temp in input().strip().split(' ')]

ans = -1 for x in a: for y in b: if x + y <= s:

ans = max(ans, x + y)

print (ans)

### Java

import java.io.*; import java.util.*; import java.text.*; import java.math.*;

import java.util.regex.*;

public class Solution {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int s = in.nextInt();

int n = in.nextInt();

int m = in.nextInt();

int[] keyboards = new int[n];

for(int keyboards_i=0; keyboards_i < n; keyboards_i++){

keyboards[keyboards_i] = in.nextInt();

}

int[] pendrives = new int[m];

for(int pendrives_i=0; pendrives_i < m; pendrives_i++){

pendrives[pendrives_i] = in.nextInt();

for(int i=0;i

} int max=0;

for(int j=0;j

if(keyboards[i]+pendrives[j]<=s){

if(max

max=keyboards[i]+pendrives[j];

} } } }

System.out.println(max==0?-1:max);

} }

Disclaimer: The above Problem (Electronics Shop) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

### Java MD5 | HackerRank Solution

स्रोत : www.codingbroz.com

Do you want to see answer or more ?
Mohammed 5 day ago

Guys, does anyone know the answer?