-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectronicsShop.java
More file actions
42 lines (39 loc) · 1.28 KB
/
ElectronicsShop.java
File metadata and controls
42 lines (39 loc) · 1.28 KB
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int getMoneySpent(int[] keyboards, int[] drives, int s, int n, int m){
// Complete this function
int amt = 0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if((keyboards[i]+drives[j])>amt&&(keyboards[i]+drives[j])<=s){
amt = keyboards[i]+drives[j];
}
}
}
if(amt>0) {
return amt;
}
else return -1;
}
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[] drives = new int[m];
for(int drives_i=0; drives_i < m; drives_i++){
drives[drives_i] = in.nextInt();
}
// The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
int moneySpent = getMoneySpent(keyboards, drives, s, n, m);
System.out.println(moneySpent);
}
}