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 } }
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
Sample Output 0
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
Sample Output 1
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): def main(): for i in range(k): hillichurls = [int(input().strip()) for i in range(h)] if __name__ == "__main__": |
The code implementation in Java
import java.io.BufferedReader; public class Solution { for(int i = 0; i < k; i++){ int[] hillichurls = new int[h]; for(int i = 0; i < h; i++) { |
Step by step
Solved in 4 steps with 3 images