File tree 1 file changed +49
-0
lines changed
HackerRank/Problem Solving/Easy 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
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<<" \n Enter " <<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<<" \n Enter " <<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<<" \n Enter the budget: " ;
45
+ cin>>b;
46
+
47
+ cout<<" \n Money Spent: " <<getMoneySpent (keyboards, drives, b);
48
+ return 0 ;
49
+ }
You can’t perform that action at this time.
0 commit comments