TechInfo

Score and Cost CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Score and Cost CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
JoinScishowEngineerTelegram

Score and Cost CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Problem Statement

There are ‘N’ games. You are given two arrays, ‘A’ and ‘B’ of length ‘N’ such that ‘A[ i ]’ represents the score you get for purchasing the ‘i-th’ game, and ‘B[ i ]’ represents the cost of the ‘i-th’ game.

Define ‘M’ to be the highest cost paid among all games you bought.

Return the minimum ‘M’ such that you can get a total score of at least ‘X’ if you can purchase exactly one game for free. Return ‘-1’ if it is impossible.

For Example :
Let 'N' = 3, 'A' = [ 3, 7, 1 ], 'B' = [ 2, 4, 4 ], 'X' = 9.
We buy the second game for free and the first for a cost of '2'.
The total score is '3 + 7 = 10', and the value of 'M' is 2.
It can be shown that this is the minimum 'M' possible.
Thus, the answer is '2'.
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= 'T' <= 10
1 <= 'N' <= 10^5
1 <= 'X, A[i], B[i]' <= 10^9

Time Limit: 1 sec
Sample Input 1 :
2
3 11
4 2 6
14 7 7
3 100
11 3 5
10 7 9
Sample Output 1 :
7
-1
Explanation Of Sample Input 1 :
First test case:-
We buy the first game for free and the other two games for a cost of '7' each.
The total score is '4 + 2 + 6 = 12', and the value of 'M' is 7.
It can be shown that this is the minimum 'M' possible.
Thus, the answer is '7'.

Second test case:-
It can be shown that it is impossible to get a total score of at least 'X'.
Thus, the answer is '-1'.
Sample Input 2 :
2
5 17
5 4 3 1 6
10 11 12 13 14
4 30
9 17 6 3
17 15 9 12
Sample Output 2 :
12
15
Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
JoinScishowEngineerTelegram


6 digit code appear after 69 seconds.
 

Wait for  Solution


We are Still Solving…. Please Visit Our Social Media Handle Till Then

Here Discuss About Score and Cost CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Score and Cost CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

 

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.

If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE