Write code in C++, C# or Python to solve the following problem: In a party there are N persons and we have M raffles. One person may participate in any number of raffles (from 0 to M). At the end of the day, host of the party comes to you and gives you M lists. Each list contains multiple integer numbers which are the "raffle ID numbers" of the participants. Then, for each list an integer number, I, is announced to determine the winner of the raffle: the winner is the person with raffle ID number K such that K is larger than exactly I numbers in that list. To help the host to find the winners you want to write a program. Input Format First line of the input is N and M. Then, there are M lines, each one contains integer numbers between 1 and N. Each list may contain at most N numbers. At the end of each line there is -1. After these lines there is one line which contains M integers to announce the winners. If the j-th number in this line is I it means that the winner of list j is the person whose ID is exactly larger than I other persons in that list. If I is larger than number of people in list j, then that list does not have a winner. Example:831423-15218637-146831-1258 Comment: there are 8 people in this party and we have 3 raffles. In the first raffle, participants' IDs are 1, 4, 2, and 3. In the second raffle, IDs are 5, 2, ... Winner of the first raffle is 3 (3 is exactly larger than 2 other numbers in that list). Winner of the second raffle is 7 (7 is larger than 1, 2, 3, 5, and 6 in the second raffle). Third raffle does not have a winner (there are only 5 participants but the winner's ID has to be larger than 8 other IDs, which is impossible). Constraints NA Output Format For each list print the ID of the winner. If there is no winner, print -1. Example: For the example in the Input part we will have: 3 7 -1   Sample Input 0 8 3 1 4 2 3 -1 5 2 1 8 6 3 7 -1 4 6 8 3 1 -1 2 5 8 Sample Output 0 3 7

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

Write code in C++, C# or Python to solve the following problem:

In a party there are N persons and we have M raffles. One person may participate in any number of raffles (from 0 to M). At the end of the day, host of the party comes to you and gives you M lists. Each list contains multiple integer numbers which are the "raffle ID numbers" of the participants. Then, for each list an integer number, I, is announced to determine the winner of the raffle: the winner is the person with raffle ID number K such that K is larger than exactly I numbers in that list. To help the host to find the winners you want to write a program.

Input Format

First line of the input is N and M. Then, there are M lines, each one contains integer numbers between 1 and N. Each list may contain at most N numbers. At the end of each line there is -1. After these lines there is one line which contains M integers to announce the winners. If the j-th number in this line is I it means that the winner of list j is the person whose ID is exactly larger than I other persons in that list. If I is larger than number of people in list j, then that list does not have a winner.

Example:831423-15218637-146831-1258

Comment: there are 8 people in this party and we have 3 raffles. In the first raffle, participants' IDs are 1, 4, 2, and 3. In the second raffle, IDs are 5, 2, ... Winner of the first raffle is 3 (3 is exactly larger than 2 other numbers in that list). Winner of the second raffle is 7 (7 is larger than 1, 2, 3, 5, and 6 in the second raffle). Third raffle does not have a winner (there are only 5 participants but the winner's ID has to be larger than 8 other IDs, which is impossible).

Constraints

NA

Output Format

For each list print the ID of the winner. If there is no winner, print -1.

Example: For the example in the Input part we will have: 3 7 -1

 

Sample Input 0

8 3
1 4 2 3 -1
5 2 1 8 6 3 7 -1
4 6 8 3 1 -1
2 5 8

Sample Output 0

3
7
-1
Expert Solution
Step 1

ANSWER:-

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Linked List Representation
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