Information is present in the screenshot and below. Based on that need help in solving the code for this problem in java. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply divide-and-conquer algorithm in the problem. Make sure ALL test cases return expected outputs by providing output screenshots. Hint: Use binarySearch() Output Format The output contains one line with a single integer T_min, the minimum T needed to take out all N enemies within R rounds. If no T exists, print "A smile better suits a hero..." (without quotes) Sample Input 0 3 4 2 7 2 2 1 2 2 1 2 Sample Output 0 0 Sample Input 1 5 6 14 12 8 3 8 5 7 2 1 1 2 2 2 Sample Output 1 A smile better suits a hero... Sample Input 2 5 6 2 10 2 7 2 6 1 2 2 1 2 1 1 Sample Output 2 3
Information is present in the screenshot and below. Based on that need help in solving the code for this problem in java. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply divide-and-conquer
Hint: Use binarySearch()
Output Format
The output contains one line with a single integer T_min, the minimum T needed to take out all N enemies within R rounds.
If no T exists, print "A smile better suits a hero..." (without quotes)
Sample Input 0
3 4 2 7
2
2
1
2
2
1
2
Sample Output 0
0
Sample Input 1
5 6 14 12
8
3
8
5
7
2
1
1
2
2
2
Sample Output 1
A smile better suits a hero...
Sample Input 2
5 6 2 10
2
7
2
6
1
2
2
1
2
1
1
Sample Output 2
3
import java.io.*; public class Solution { for(int i = 0; i < n; i++) { for(int i = 0; i < k; i++) { int ans = solve(n,k,f,h,hp_i,d_j); if(ans == -1){ /* Parameters: Returns the minimum T needed to defeat all enemies, or -1 if that is impossible. |
![Continuing from "Shattering the Towers of Algorythmos," the tower is crumbling, and you
have to escape with the other Scions of the School of Turing. On the way out of the crumbling
tower, you encounter several enchanted guards whose only goal is to turn this crumbling
tower into your final resting place.
You must escape the tower to take down the other Towers of Algorythmos. Each enemy has a
pool of hit points HP₂. You have K attacks, the ith of which deals D; damage to each
enemy. If an enemy's hit points drop to 0, they are knocked unconscious. Like before, you
simply use your first attack, then the second, and so on until you reach the last attack. After
this, you return to the first attack and keep following the same sequence.
This time though, the enemies can attack you back. After each of your attacks, the enemies
that are still conscious deal F damage to you. You start with H hit points. If your hit points
drop to 0, the enemies succeed in turning this crumbling tower into your final resting place.
This is how the battle goes: you attack, then they attack. However, if it is your turn to attack
and you are below I hit points, instead of attacking, you restore your hit points to H.
You like to live a little dangerously. Can you determine the lowest possible T such that you
can take out all enemies and escape from the crumbling tower?
Input Format
Input begins with a line containing two space-separated integers N, K, F, and H, indicating
the number of enemies, your number of attacks, the damage dealt by each enemy, and your
starting hit points.
N lines follow, each containing a single integer HP;, the hit points of the ith enemy.
K lines follow, each containing a single integer D;, the damage dealt by your jth attack.
Constraints
1 ≤ N, K, Dj, HP; ≤ 105
1 ≤ F, H ≤ 10⁹](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fef7c41bc-9ec8-4b0d-8392-fba4e5be0a35%2Fe07a8498-36a5-4b2f-85b2-baa7c4a264ff%2Fyu8p40e_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)