are given n chains of lengths l1,l2,… ,ln. You intend to fabricate a tree utilizing some of them.    Every vertex of the tree is either white or dark.    The tree at first just has a white root vertex.

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

Correct answer will be upvoted else Multiple Downvoted. Computer science.

 

 

You are given n chains of lengths l1,l2,… ,ln. You intend to fabricate a tree utilizing some of them. 

 

Every vertex of the tree is either white or dark. 

 

The tree at first just has a white root vertex. 

 

All chains at first comprise just of white vertices. 

 

You can take one of the chains and interface any of its vertices to any white vertex of the tree with an edge. The chain turns out to be important for the tree. The two endpoints of this edge become dark. 

 

Each chain can be utilized close to once. 

 

A few chains can be left unused. 

 

The distance between two vertices of the tree is the number of edges on the most brief way between them. 

 

Assuming there is essentially k white vertices in the subsequent tree, the worth of the tree is the distance between the root and the k-th nearest white vertex. 

 

What's the base worth of the tree you can get? In case it is absolutely impossible to construct a tree with basically k white vertices, then, at that point, print - 1. 

 

Input 

 

The principal line contains two integers n and k (1≤n≤2⋅105, 2≤k≤109) — the number of chains and the base number of white vertices a tree ought to must have a worth. 

 

The subsequent line contains n integers l1,l2,… ,ln (3≤li≤2⋅105) — the lengths of the chains. 

 

Output 

 

Print a solitary integer. In case it is absolutely impossible to construct a tree with essentially k white vertices, then, at that point, print - 1. In any case, print the base worth the tree can have

 

 

 

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Types of trees
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