Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python or java. The time complexity has to be as less as possible. Output Format Output K lines, each containing the name of the knight and an integer indicating the number of hillichurls they can defeat with their optimal attack separated by a single space. The knights must be sorted in non-ascending order according to the number of hillichurls defeated. In the case of a tie between two knights, print them in lexicographical order. Sample Input 0 3 5 Amber 101 47 13 33 11 Kaeya 473 16 36 49 47 Fischl 263 39 10 42 14 49 14 358 444 306 Sample Output 0 Fischl 2 Kaeya 2 Amber 1 Explanation 0 Amber's most powerful skill is her normal attack with 47% scaling. This deals 101 * 0.47 = 47.47 = 47 damage, which can defeat 1 hillichurl, which is the second one. Kaeya's most powerful skill is his elemental skill, with 49% scaling. This deals 473 * 0.49 = 231.77 = 231 damage, which can defeat the first 2 hillichurls. Fischl's most powerful skill is her elemental skill, with 42% scaling. This deals 263 * 0.42 = 110.46 = 110 damage, which can defeat the first 2 hillichurls. In printing the rankings, Fischl and Kaeya both defeated 2 hillichurls, so they are printed in lexicographical order, with Fischl before Kaeya. Sample Input 1 2 6 Timmie 9000 1000 100 500 100 Diluc 518 29 39 42 237 318 257 1490 3980 1960 3350 Sample Output 1 Timmie 6 Diluc 2 Explanation 1 Timmie's most powerful skill is his normal attack with 1000% scaling. This deals 9000 * 10.00 = 90000.00 = 90000 damage, which can defeat all 6 hillichurls. Diluc's most powerful skill is his elemental burst, with 237% scaling. This deals 518 * 2.37 = 1227.66 = 1227 damage, which can defeat the first 2 hillichurls. There are no ties, so Timmie is the top ranked Knight of Favonius, followed by Diluc. #Timmie6Star The code implementation in Python def solve(k,h,knights,hillichurls):     # compute and print answer here def main():     k, h = list(map(int,input().strip().split(" ")))     knights = []     for i in range(k):         name = input().strip()         temp = list(map(int,input().strip().split(" ")))         knights.append((name,temp))     hillichurls = [int(input().strip()) for i in range(h)]     solve(k,h,knights,hillichurls) if __name__ == "__main__":     main() The code implementation in Java import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Solution {     public static void main(String[] args) throws Exception {         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         StringBuilder sb = new StringBuilder();                  String[] parts = br.readLine().trim().split(" ");         int k = Integer.parseInt(parts[0]);         int h = Integer.parseInt(parts[1]);         String[] names = new String[k];         int[] atks = new int[k];         int[][] scaling = new int[k][4];         for(int i = 0; i < k; i++){             names[i] = br.readLine().trim();             parts = br.readLine().trim().split(" ");             atks[i] = Integer.parseInt(parts[0]);             for(int j = 1; j < 5; j++) {                 scaling[i][j - 1] = Integer.parseInt(parts[j]);             }         }         int[] hillichurls = new int[h];         for(int i = 0; i < h; i++) {             hillichurls[i] = Integer.parseInt(br.readLine().trim());         }         // study how to append to StringBuilder to optimize output runtime         solve(k,h,names,atks,scaling,hillichurls,sb);         System.out.print(sb);     }          /**      * Parameters:      * k : int - number of knights      * h : int - number of hillichurls      * names : array-like of shape (k,)       - list of knight names in order       *                                          given in input file      * atks : array-like of shape (k,)        - list of atk stats in order given       *                                          in input file      * scalings : array-like of shape (k,4)   - matrix of scaling values in        *                                          order given in input file. Each       *                                          row contains (NA,CA,ES,EB)      * hillichurls : array-like of shape (h,) - list of hillichurl hit points in       *                                          order given in input file      * sb : StringBuilder                     - StringBuilder to store output      */     public static void solve(int k, int h, String[] names, int[] atks,                               int[][] scaling, int[] hillichurls,                               StringBuilder sb){         // compute and build output in StringBuilder sb here              } }

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 or java. The time complexity has to be as less as possible.

Output Format

Output K lines, each containing the name of the knight and an integer indicating the number of hillichurls they can defeat with their optimal attack separated by a single space. The knights must be sorted in non-ascending order according to the number of hillichurls defeated. In the case of a tie between two knights, print them in lexicographical order.

Sample Input 0

3 5
Amber
101 47 13 33 11
Kaeya
473 16 36 49 47
Fischl
263 39 10 42 14
49
14
358
444
306

Sample Output 0

Fischl 2
Kaeya 2
Amber 1

Explanation 0

Amber's most powerful skill is her normal attack with 47% scaling. This deals 101 * 0.47 = 47.47 = 47 damage, which can defeat 1 hillichurl, which is the second one.

Kaeya's most powerful skill is his elemental skill, with 49% scaling. This deals 473 * 0.49 = 231.77 = 231 damage, which can defeat the first 2 hillichurls.

Fischl's most powerful skill is her elemental skill, with 42% scaling. This deals 263 * 0.42 = 110.46 = 110 damage, which can defeat the first 2 hillichurls.

In printing the rankings, Fischl and Kaeya both defeated 2 hillichurls, so they are printed in lexicographical order, with Fischl before Kaeya.

Sample Input 1

2 6
Timmie
9000 1000 100 500 100
Diluc
518 29 39 42 237
318
257
1490
3980
1960
3350

Sample Output 1

Timmie 6
Diluc 2

Explanation 1

Timmie's most powerful skill is his normal attack with 1000% scaling. This deals 9000 * 10.00 = 90000.00 = 90000 damage, which can defeat all 6 hillichurls.

Diluc's most powerful skill is his elemental burst, with 237% scaling. This deals 518 * 2.37 = 1227.66 = 1227 damage, which can defeat the first 2 hillichurls.

There are no ties, so Timmie is the top ranked Knight of Favonius, followed by Diluc. #Timmie6Star

The code implementation in Python

def solve(k,h,knights,hillichurls):
    # compute and print answer here

def main():
    k, h = list(map(int,input().strip().split(" ")))
    knights = []

    for i in range(k):
        name = input().strip()
        temp = list(map(int,input().strip().split(" ")))
        knights.append((name,temp))

    hillichurls = [int(input().strip()) for i in range(h)]
    solve(k,h,knights,hillichurls)

if __name__ == "__main__":
    main()

The code implementation in Java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Solution {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        
        String[] parts = br.readLine().trim().split(" ");
        int k = Integer.parseInt(parts[0]);
        int h = Integer.parseInt(parts[1]);
        String[] names = new String[k];
        int[] atks = new int[k];
        int[][] scaling = new int[k][4];

        for(int i = 0; i < k; i++){
            names[i] = br.readLine().trim();
            parts = br.readLine().trim().split(" ");
            atks[i] = Integer.parseInt(parts[0]);
            for(int j = 1; j < 5; j++) {
                scaling[i][j - 1] = Integer.parseInt(parts[j]);
            }
        }

        int[] hillichurls = new int[h];

        for(int i = 0; i < h; i++) {
            hillichurls[i] = Integer.parseInt(br.readLine().trim());
        }
        // study how to append to StringBuilder to optimize output runtime
        solve(k,h,names,atks,scaling,hillichurls,sb);
        System.out.print(sb);
    }
    
    /**
     * Parameters:
     * k : int - number of knights
     * h : int - number of hillichurls
     * names : array-like of shape (k,)       - list of knight names in order 
     *                                          given in input file
     * atks : array-like of shape (k,)        - list of atk stats in order given 
     *                                          in input file
     * scalings : array-like of shape (k,4)   - matrix of scaling values in  
     *                                          order given in input file. Each 
     *                                          row contains (NA,CA,ES,EB)
     * hillichurls : array-like of shape (h,) - list of hillichurl hit points in 
     *                                          order given in input file
     * sb : StringBuilder                     - StringBuilder to store output
     */
    public static void solve(int k, int h, String[] names, int[] atks, 
                             int[][] scaling, int[] hillichurls, 
                             StringBuilder sb){
        // compute and build output in StringBuilder sb here
        
    }
}

Jean Gunnhildr, Acting Grand Master of the Knights of Favonius, intends to test the combat efficiency of
the members of her organization. Despite the odd assortment of characters at her disposal (among
which includes a child with a penchant for violence, a creepy dude who is fond of giving people the cold
shoulder, an alchemist with a stare that is perhaps a bit too intense, an absent-minded gliding
instructor with an exploding doll), she thinks they are capable fighters.
However, she would still like to perform a classical "DPS Check" as she gathers data in order to more
efficiently assign missions to the Knights of Favonius.
To explain this, we will be using a simplified version of Genshin Impact's mechanics.
Each character has an ATK stat. The character then has four attacks: a normal attack, charged attack,
elemental skill, and elemental burst.
Each of these four attack types have a scaling factor. This determines how much damage is dealt
relative to the attack. For example, if a character has 1523 ATK and their normal attack has 67%
scaling, their normal attack would deal 1523 · 67% = 1523 -0.67 = 1020.41 damage. After this,
damage is always rounded down. The final damage for the normal attack is 1020.
Jean has gathered a sizable amount of data involving hillichurls. For our purposes, we will abstract the
consititution of these hillichurls using the concept of hit points. A hillichurl will have a fixed number of
hit points. When a character attacks this hillichurl, their hit points are decreased by the damage dealt.
When the hillichurl's hit points drop to 0 or lower, the hillichurl is defeated.
Given the number of hillchurls in the sample Jean collected, and the ATK stats and damage scaling of
each of the moves of her Knights of Favonius, kindly print the ranking of all her knights in terms of
most hillichurls defeated. You may assume that each character always uses their most effective move
and the damage is applied exactly once to each of the hypothetical hillichurls in Jean's sample. See the
sample input for an explanation of how this would look like.
Transcribed Image Text:Jean Gunnhildr, Acting Grand Master of the Knights of Favonius, intends to test the combat efficiency of the members of her organization. Despite the odd assortment of characters at her disposal (among which includes a child with a penchant for violence, a creepy dude who is fond of giving people the cold shoulder, an alchemist with a stare that is perhaps a bit too intense, an absent-minded gliding instructor with an exploding doll), she thinks they are capable fighters. However, she would still like to perform a classical "DPS Check" as she gathers data in order to more efficiently assign missions to the Knights of Favonius. To explain this, we will be using a simplified version of Genshin Impact's mechanics. Each character has an ATK stat. The character then has four attacks: a normal attack, charged attack, elemental skill, and elemental burst. Each of these four attack types have a scaling factor. This determines how much damage is dealt relative to the attack. For example, if a character has 1523 ATK and their normal attack has 67% scaling, their normal attack would deal 1523 · 67% = 1523 -0.67 = 1020.41 damage. After this, damage is always rounded down. The final damage for the normal attack is 1020. Jean has gathered a sizable amount of data involving hillichurls. For our purposes, we will abstract the consititution of these hillichurls using the concept of hit points. A hillichurl will have a fixed number of hit points. When a character attacks this hillichurl, their hit points are decreased by the damage dealt. When the hillichurl's hit points drop to 0 or lower, the hillichurl is defeated. Given the number of hillchurls in the sample Jean collected, and the ATK stats and damage scaling of each of the moves of her Knights of Favonius, kindly print the ranking of all her knights in terms of most hillichurls defeated. You may assume that each character always uses their most effective move and the damage is applied exactly once to each of the hypothetical hillichurls in Jean's sample. See the sample input for an explanation of how this would look like.
Input Format
The first line contains two space-separated integers K and H indicating the number of knights and
hillichurls to be considered in the problem.
2K lines follow, with every two lines describing one of Jean's Knights. The line will start with a single
string indicating the knight's name. This string will only contain latin alphabet characters. All the names
are guaranteed to be distinct. The next line contains five integers ATK, NA, CA₁, ESį, EBį
indicating the ATK stat, normal attack scaling, charged attack scaling, elemental skill scaling, and
elemental burst scaling of the ith character.
After all the knight description, H lines follow, each containing a single integer H;, indicating the hit
points of each of the hillichurls in Jean's sample.
Constraints
1≤K, H ≤ 105
1 ≤ ATK; ≤9.10³
1 ≤ NA, CA, ES, EB; < 10³
1 ≤ H; ≤ 105 for all 1 ≤ i ≤ H
Transcribed Image Text:Input Format The first line contains two space-separated integers K and H indicating the number of knights and hillichurls to be considered in the problem. 2K lines follow, with every two lines describing one of Jean's Knights. The line will start with a single string indicating the knight's name. This string will only contain latin alphabet characters. All the names are guaranteed to be distinct. The next line contains five integers ATK, NA, CA₁, ESį, EBį indicating the ATK stat, normal attack scaling, charged attack scaling, elemental skill scaling, and elemental burst scaling of the ith character. After all the knight description, H lines follow, each containing a single integer H;, indicating the hit points of each of the hillichurls in Jean's sample. Constraints 1≤K, H ≤ 105 1 ≤ ATK; ≤9.10³ 1 ≤ NA, CA, ES, EB; < 10³ 1 ≤ H; ≤ 105 for all 1 ≤ i ≤ H
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Problems on numbers
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
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