Apna Hindi Tech Website Computer science के Students और Technology के बारे में जानकारी रखने वाले लोगों के लिए बहुत लाभदायक Web site है।
हमारी Website Apna Hindi Tech पर Free में Python Programming language हिंदी में सिखाई जाती है और दुनिया में जो लेटेस्ट टेक्नोलॉजी(Technology) है उसके बारे में विस्तार से बताया जाता है।
दोस्तों हमने अपनी वेबसाइट Apna Hindi Tech पर Python Programming से रिलेटेड बहुत सारे Softwares बनाना भी सिखाया है वो भी अपनी भाषा हिंदी में।
Maximize It Hackerrank Solution Python
Maximize It! Hackerrank Solution Python 3
Hello Friends
आज हम आपको Hacker Rank पर Maximize It का कंप्लीट सॉल्यूशन बताएंगे वह भी आसान भाषा में। तो दोस्तों चलिए जानते हैं सॉल्यूशन ।
Problem : Maximize It! Hackerrank Solution
You are given a function f(x) = x^2. You are also given k lists. The ith 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(Xk))%M
Xi denotes the element picked from the ith list . Find the maximized value Smax 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.
S = ( f(X1) + f(X2) + ......+ f(Xk))%M
Xi denotes the element picked from the ith list . Find the maximized value Smax 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.
Input Format :
The first line contains 2 space separated integers K and M.The next K lines each contains an integer Ni, denoting the number of elements in the ith list, followed by Ni space separated integers denoting the elements in the list.
Constraints :
1 <= K <= 71 <= M <= 1000
1 <= Ni <= 7
1 <= magnitude of element in list <= 10^9
Output Format :
Output a single integer denoting the value Smax.
Sample Input :
3 1000
2 5 4
3 7 8 9
5 5 7 8 9 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 (5^2 + 9^2 + 10^2)%1000 =206.
Solution :
from itertools import product n,m=input().split() y=int(m) l=[] for i in range(int(n)): x=list(map(int,input().split()))[1:] l.append(x) s=map(lambda x:sum(i*i for i in x)%y,product(*l)) print(max(s)) |
Other Articles
DISCLAIMER
The above hole problem statement is given by hackerrank.com but the solution is generated by the Apna Hindi Tech authority if any of the query regarding this post or website fill the following contact form.
......Thank You......
Post a Comment
Post a Comment