-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathElectronicsStore.cpp
More file actions
41 lines (37 loc) · 953 Bytes
/
ElectronicsStore.cpp
File metadata and controls
41 lines (37 loc) · 953 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
#include <bits/stdc++.h>
using namespace std;
long int getMoneySpent(long int keyboards[],long int drives[], int s,int n,int m){
long int sum,max=-1;
sort(keyboards,keyboards+n);
sort(drives,drives+m);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
sum=keyboards[i]+drives[j];
if(sum>s)
break;
if(sum>max)
max=sum;
}
}
return max;
}
int main() {
int s;
int n;
int m;
cin >> s >> n >> m;
long int keyboards[n];
for(int keyboards_i = 0; keyboards_i < n; keyboards_i++){
cin >> keyboards[keyboards_i];
}
long int drives[m];
for(int drives_i = 0; drives_i < m; drives_i++){
cin >> drives[drives_i];
}
// The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
long int moneySpent = getMoneySpent(keyboards, drives, s,n,m);
cout << moneySpent << endl;
return 0;
}