Pytnon following You are given a function f(X) = X^2. You are also given K lists. The i th list consists of N i elements. You have to pick one element from each list so that the value from he equation below is maximized: S (f (X1) + f(X2) +....+f(X k ))%M Ki denotes the element picked from the i th list . Find the maximized value S max obtained. % denotes the modulo operator. Note that you need to take exactly one element from each list, not necessarily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that you can obtain, will be the answer to the problem. nput Format : The first line contains 2 space separated integers K and M. The next K lines each contains an integer N i , denoting the number of elements in the i th ist, followed by N i space separated integers denoting the elements in the list. [1<=K<=7 1<=M<=1000 1<=Ni <=7 1<=Magnitude of elements in list <= 10 9] Dutput Format : Output a single integer denoting the value S max. Sample Input : 3 1000 254 3789 55789 10 Sample Output : 206 Explanation : Picking 5 from the 1st list, 9 from the 2nd list and 10 from the 3rd list gives the maximum S value equal to (52 + 92 102)% 1000 = 206.

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
Write a python Code for the following:
You are given a function f(X) = X^2. You are also given K lists. The i th list consists of Ni elements. You have to pick one element from each list so that the value from
the equation below is maximized:
S (F (X1) + f(X2) +.. +f{X k ))%M
Xi denotes the element picked from the i th list . Find the maximized value S max obtained. % denotes the modulo operator. Note that you need to take exactly one
element from each list, not necessanily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that
you can obtain, will be the answer to the problem.
Input Format : The first line contains 2 space separated integers K and M. The next K lines each contains an integer N i, denoting the number of elements in the i th
list, followed by Ni space separated integers denoting the elements in the list. [1<=K<=7 1<=M<=1000 1<=N i <=7 1<=Magnitude of elements in list <= 10 9]
Output Format : Output a single integer denoting the value S max .
Sample Input :
3 1000
254
3789
55789 10
Sample Output : 206
Explanation : Picking 5 from the 1st list, 9 from the 2nd list and 10 from the 3rd list gives the maximum S value equal to (52 + 92 102)% 1000 = 206.
Transcribed Image Text:Write a python Code for the following: You are given a function f(X) = X^2. You are also given K lists. The i th list consists of Ni elements. You have to pick one element from each list so that the value from the equation below is maximized: S (F (X1) + f(X2) +.. +f{X k ))%M Xi denotes the element picked from the i th list . Find the maximized value S max obtained. % denotes the modulo operator. Note that you need to take exactly one element from each list, not necessanily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that you can obtain, will be the answer to the problem. Input Format : The first line contains 2 space separated integers K and M. The next K lines each contains an integer N i, denoting the number of elements in the i th list, followed by Ni space separated integers denoting the elements in the list. [1<=K<=7 1<=M<=1000 1<=N i <=7 1<=Magnitude of elements in list <= 10 9] Output Format : Output a single integer denoting the value S max . Sample Input : 3 1000 254 3789 55789 10 Sample Output : 206 Explanation : Picking 5 from the 1st list, 9 from the 2nd list and 10 from the 3rd list gives the maximum S value equal to (52 + 92 102)% 1000 = 206.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

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