Skip to content

Commit f6c6602

Browse files
committed
Electronic Shop
1 parent 6232ef5 commit f6c6602

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// https://www.hackerrank.com/challenges/electronics-shop/problem?isFullScreen=true
2+
3+
// Electronic Shop
4+
5+
#include<iostream>
6+
#include<vector>
7+
using namespace std;
8+
9+
int getMoneySpent(vector<int> keyboards, vector<int> drives, int b) {
10+
long long int spent = -1;
11+
int n = keyboards.size();
12+
int m = drives.size();
13+
for (int i =0; i<n; i++) {
14+
for (int j=0; j<m; j++) {
15+
long long int sum = keyboards[i] + drives[j];
16+
if (sum <= b) {
17+
spent = max(spent, sum);
18+
}
19+
}
20+
}
21+
return spent;
22+
}
23+
24+
int main(int argc, char const *argv[])
25+
{
26+
int n, m, b;
27+
cout<<"Enter the number of keyboards and drives: ";
28+
cin>>n>>m;
29+
vector<int> keyboards, drives;
30+
cout<<"\nEnter "<<n<<" prices of keyboards: ";
31+
for (int i = 0; i < n; ++i)
32+
{
33+
int value;
34+
cin>>value;
35+
keyboards.push_back(value);
36+
}
37+
cout<<"\nEnter "<<m<<" prices of drives: ";
38+
for (int i = 0; i < m; ++i)
39+
{
40+
int value;
41+
cin>>value;
42+
drives.push_back(value);
43+
}
44+
cout<<"\nEnter the budget: ";
45+
cin>>b;
46+
47+
cout<<"\nMoney Spent: "<<getMoneySpent(keyboards, drives, b);
48+
return 0;
49+
}

0 commit comments

Comments
 (0)