-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate-Shopping-Techgig.java
More file actions
106 lines (91 loc) · 3.05 KB
/
Date-Shopping-Techgig.java
File metadata and controls
106 lines (91 loc) · 3.05 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Date Shopping (100 Marks)
Varun has got a date after a long time and wants to look his best for his partner.
He decides to go shopping to buy a new t-shirt and a pair of jeans but since it is the month’s end, he has a budget of only B rupees.
He wants to spend the maximum money on jeans and t-shirt combo within the given budget. The problem is that he is good with his cloth choices but not with the calculations and asks for your help.
Varun has selected T t-shirts and J jeans. He provides you the prices of each of them and you have to determine the maximum money he can spend shopping.
If it is not possible to buy the jeans and t-shirt with the given budget, you can tell him -1.
Example: 1
Budget, B = 20
Jeans, Ji = [ 10, 5, 8 ]
T-shirts, Ti = [ 11, 7, 4 ]
The maximum money he can spend is 19 by buying the J3 jeans along with the T1 t-shirt.
Example: 2
Budget, B = 10
Jeans, Ji = [ 8 , 9 , 10 ]
T-shirt, Ti = [ 4, 6, 3 ]
With the given budget, it is not possible for Varun to buy the jeans and t-shirt both. Thus, the maximum money he can spend is -1.
Can you help him shop and get ready for his date?
Input Format
The first line of input consists of the Budget, B
The second line of input consists of the number of jeans (J) and number of t-shirts (T) space-separately.
The third line of input consists of the J space-separated jeans prices, Ji
The fourth line of input consists of the T space-separated t-shirt prices, Ti
Constraints
1<= B <=10^6
1<= J, T <=1000
1<= Ji, Ti =10^6
Output Format
Print the maximum money Varun can spend shopping.
Sample TestCase 1
Input
10
3 3
5 7 9
6 2 7
Output
9
Explanation
The maximum money can be spent by selecting J2 jeans and T2 t-shirt.
Maximum money = 7 + 2 = 9
*/
import java.io.*;
import java.util.*;
public class CandidateCode {
public static void main(String args[] ) throws Exception {
Scanner sc=new Scanner(System.in);
int b=sc.nextInt();
int a=sc.nextInt();
int bl=sc.nextInt();
int arr[]=new int[a];
int brr[]=new int[b];
for(int i=0;i<a;i++)
{
arr[i]=sc.nextInt();
}
for(int i=0;i<bl;i++)
{
brr[i]=sc.nextInt();
}
int k=0;
int mn=0;
int pre=-1;
int flag=0;
for(int i=0;i<a;i++)
{
for(int j=0;j<bl;j++)
{
int s=arr[i]+brr[j];
if(s<=b && flag==0)
{
pre=s;
// System.out.println(f[k]+"fis");
flag=1;
}
else if(s<=b && flag!=0)
{
mn=s;
if(mn>pre)
{
pre=mn;
}
// System.out.println(f[k]+"sec");
}
else{
}
k=k+1;
}
}
System.out.println(pre);
}
}