Every universe in the infinite Omniverse is now unstable due to unforeseen circumstances. Doctor Bizarro cannot save all realities, but through a strategic use of his abilities, perhaps he can save some realities to give them enough time to branch off and repopulate the Omniverse. Within reach of Doctor Bizarro's powers are N universes. Unfortunately, all universes outside his reach are doomed and will no longer be of concern in this scenario. Each universe has an instability index X₂. Doctor Bizarro can choose two universes within his powers' reach and collide them with an incursion to merge their realities. This will cause their instability indices to be added up. Doctor Bizarro can perform up to K incursions before his power corrupts his mind with insanity. Doctor Bizarro's goal is to use his K incursions to minimize the maximum instability index among the remaining universes. Can you find the smallest possible maximum instability assuming you perform the incursions optimally? Input Format Each test case begins with a line containing two space-separated integers N and K, indicating the number of universes in Doctor Bizarro's reach and the number of incursions he must perform, respectively. N lines follow, each containing a single integer X₁, the instability index of the ith universe. Constraints 1≤K

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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 greedy algorithm in the problem. Make sure both test cases return correct answers.

Output Format

The output consists of one line containing a single integer denoting the smallest possible maximum instability index among all the remaining universes.

Sample Input 0
5 2
1
3
1
3
4

Sample Output 0
5

Sample Input 1
6 4
8
7
5
8
7
6

Sample Output 1
25

Sample Input 2
8 7
13
8
13
3
3
10
5
4

Sample Output 2
59

The actual code

"""
This function solves a test case.

Parameters:
n : int - number of universes
k : int - number of incursions
xs : array-like - list of instability indices

Returns:
An integer indicating the smallest maximum instability indices of the remaining
universes
"""
def solve(n,k,xs):
    # TODO
    pass

n,k = list(map(int,input().strip().split(" ")))

xs = [int(input()) for i in range(n)]

print(f"{solve(n,k,xs)}\n")

Every universe in the infinite Omniverse is now unstable due to unforeseen circumstances. Doctor Bizarro
cannot save all realities, but through a strategic use of his abilities, perhaps he can save some realities to give
them enough time to branch off and repopulate the Omniverse.
Within reach of Doctor Bizarro's powers are N universes. Unfortunately, all universes outside his reach are
doomed and will no longer be of concern in this scenario. Each universe has an instability index Xį. Doctor
Bizarro can choose two universes within his powers' reach and collide them with an incursion to merge their
realities. This will cause their instability indices to be added up. Doctor Bizarro can perform up to K
incursions before his power corrupts his mind with insanity.
Doctor Bizarro's goal is to use his K incursions to minimize the maximum instability index among the
remaining universes. Can you find the smallest possible maximum instability assuming you perform the
incursions optimally?
Input Format
Each test case begins with a line containing two space-separated integers N and K, indicating the number of
universes in Doctor Bizarro's reach and the number of incursions he must perform, respectively.
N lines follow, each containing a single integer X₁, the instability index of the ith universe.
Constraints
1≤K<N≤ 2.105
1 ≤ X₁ ≤ 10⁹
Transcribed Image Text:Every universe in the infinite Omniverse is now unstable due to unforeseen circumstances. Doctor Bizarro cannot save all realities, but through a strategic use of his abilities, perhaps he can save some realities to give them enough time to branch off and repopulate the Omniverse. Within reach of Doctor Bizarro's powers are N universes. Unfortunately, all universes outside his reach are doomed and will no longer be of concern in this scenario. Each universe has an instability index Xį. Doctor Bizarro can choose two universes within his powers' reach and collide them with an incursion to merge their realities. This will cause their instability indices to be added up. Doctor Bizarro can perform up to K incursions before his power corrupts his mind with insanity. Doctor Bizarro's goal is to use his K incursions to minimize the maximum instability index among the remaining universes. Can you find the smallest possible maximum instability assuming you perform the incursions optimally? Input Format Each test case begins with a line containing two space-separated integers N and K, indicating the number of universes in Doctor Bizarro's reach and the number of incursions he must perform, respectively. N lines follow, each containing a single integer X₁, the instability index of the ith universe. Constraints 1≤K<N≤ 2.105 1 ≤ X₁ ≤ 10⁹
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY