Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. 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. 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

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

Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. 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.

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

The actual code

"""
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.
"""
def solve(n,k,f,h,hp_i,d_j):
    # TODO

n,k,f,h = list(map(int,input().strip().split(" ")))
hp_i = [int(input().strip()) for i in range(n)]
d_j = [int(input().strip()) for i in range(k)]

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

if ans == -1:
    print("A smile better suits a hero...")
else:
    print(ans)

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⁹
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 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⁹
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Bare Bones Programming Language
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