Urgent!!!!!! Need help in answering this question based on the information attached in the screenshot. The code should be in Java and should  be able to pass all the  test cases mentioned. We have to use a divide and conquer or  a Greedy algorithm based on problem. Also the time complexity has to be as small as possible i.e the most optimal solution. If you use any references to get the code please link it as well. For reference this is the incomplete java code

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Urgent!!!!!! Need help in answering this question based on the information attached in the screenshot. The code should be in Java and should  be able to pass all the  test cases mentioned. We have to use a divide and conquer or  a Greedy algorithm based on problem. Also the time complexity has to be as small as possible i.e the most optimal solution. If you use any references to get the code please link it as well.

For reference this is the incomplete java code

import java.io.*;
import java.util.Arrays;

public class Solution {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] parts = br.readLine().trim().split(" ");
        int n = Integer.parseInt(parts[0]);
        int k = Integer.parseInt(parts[1]);
        int f = Integer.parseInt(parts[2]);
        int h = Integer.parseInt(parts[3]);
        int[] hp_i = new int[n];
        int[] d_j = new int[k];

        for(int i = 0; i < n; i++) {
            hp_i[i] = Integer.parseInt(br.readLine());
        }

        for(int i = 0; i < k; i++) {
            d_j[i] = Integer.parseInt(br.readLine());
        }

        int ans = solve(n,k,f,h,hp_i,d_j);

        if(ans == -1){
            System.out.println("A smile better suits a hero...");
        } else {
            System.out.println(ans);
        }
    }

    /*
    Solves a single test case.

    Parameters:
    n    : int        - number of enemies
    k    : int        - number of attacks
    f    : int        - damage dealt by each conscious enemy each round
    h    : int        - your max hit points
    hp_i : array-like - list of shape (n,) containing the hp of each enemy
    d_j  : array-like - list of shape (k,) containing the damage dealt by each of 
                        your attacks

    Returns the minimum T needed to defeat all enemies, or -1 if that is impossible.
    */
    public static int solve(int n, int k, long f, long h, int[] hp_i, int[] d_j) {
        // TODO
        return -2;
    }
}

Sample Input 0
3427
2
NNNN-
2
1
2
2
1
2
Sample Output 0
Sample Input 1
5 6 14 12
in 00 00 IN TAN
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
SNTNHNNAN-
2
7
2
6
1
2
2
1
2
1
1
Sample Output 2
3
Transcribed Image Text:Sample Input 0 3427 2 NNNN- 2 1 2 2 1 2 Sample Output 0 Sample Input 1 5 6 14 12 in 00 00 IN TAN 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 SNTNHNNAN- 2 7 2 6 1 2 2 1 2 1 1 Sample Output 2 3
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
T 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, D₁, HP; ≤ 105
1 ≤ F, H ≤ 10⁹
Output Format
Output contains one line with a single integer Tmin, the minimum I 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
Transcribed Image Text: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 T 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, D₁, HP; ≤ 105 1 ≤ F, H ≤ 10⁹ Output Format Output contains one line with a single integer Tmin, the minimum I 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
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education