-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0047.cpp
More file actions
42 lines (38 loc) · 849 Bytes
/
E0047.cpp
File metadata and controls
42 lines (38 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Problem Statement: https://www.hackerrank.com/challenges/electronics-shop/problem
*/
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
int getMoneySpent(vector<int> keyboards, vector<int> drives, int b) {
int max = -1;
sort(keyboards.begin(), keyboards.end(), greater<int>());
sort(drives.begin(), drives.end());
for(int i=0 ; i<keyboards.size() ; i++)
for(int j=0 ; j<drives.size() ; j++){
int sum = keyboards[i] + drives[j];
if(sum > b)
break;
else if(sum > max)
max = sum;
}
return max;
}
int main()
{
int b, n, m, num;
vector<int> keyboards, drives;
cin>>b>>n>>m;
for(int i=0 ; i<n ; i++){
cin>>num;
keyboards.push_back(num);
}
for(int i=0 ; i<m ; i++){
cin>>num;
drives.push_back(num);
}
cout<<getMoneySpent(keyboards, drives, b);
return 0;
}