message
stringlengths
2
30.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
237
109k
cluster
float64
10
10
__index_level_0__
int64
474
217k
Provide tags and a correct Python 3 solution for this coding contest problem. 'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is ai points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price. The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again. All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m distinct integers bi (1 ≤ bi ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n. Output In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type. Examples Input 4 1 1 3 7 5 3 Output 18 Input 3 2 10 3 8 2 3 Output 40 Input 2 2 100 200 1 2 Output 400
instruction
0
68,483
10
136,966
Tags: greedy, math Correct Solution: ``` n,m = map(int,input().split()) mat = list(map(int,input().split())) auction = list(map(int,input().split())) aucpoint = [mat[i-1] for i in auction] aucpoint.sort(reverse = True) for i in auction: mat[i-1] = 0 s = sum(mat) for point in aucpoint: if s > point: s *= 2 else: s += point print(s) ```
output
1
68,483
10
136,967
Provide tags and a correct Python 3 solution for this coding contest problem. 'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is ai points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price. The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again. All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m distinct integers bi (1 ≤ bi ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n. Output In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type. Examples Input 4 1 1 3 7 5 3 Output 18 Input 3 2 10 3 8 2 3 Output 40 Input 2 2 100 200 1 2 Output 400
instruction
0
68,484
10
136,968
Tags: greedy, math Correct Solution: ``` # your code goes herefrom collections import defaultdict import bisect from itertools import accumulate, count import os import sys import math from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def input(): return sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) r2=0 a=[0]+a auction=[] for i in range(0,len(b)): auction.append(a[b[i]]) a[b[i]]=-1 for i in range(1,len(a)): if a[i]!=-1: r2+=a[i] r1=r2 auction.sort() for i in range(0,len(auction)): if auction[i]<r2: r2=r2*2 else: r2+=auction[i] for i in range(len(auction)-1,-1,-1): if auction[i]<r1: r1+=r1 else: r1+=auction[i] print(max(r2,r1)) ```
output
1
68,484
10
136,969
Provide tags and a correct Python 3 solution for this coding contest problem. 'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is ai points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price. The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again. All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m distinct integers bi (1 ≤ bi ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n. Output In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type. Examples Input 4 1 1 3 7 5 3 Output 18 Input 3 2 10 3 8 2 3 Output 40 Input 2 2 100 200 1 2 Output 400
instruction
0
68,485
10
136,970
Tags: greedy, math Correct Solution: ``` n, m = list(map(int, input().split())) lst = list(map(int, input().split())) au = list(map(int, input().split())) res = sum(lst) ls = [] for i in range(m): res -= lst[au[i] - 1] ls.append(lst[au[i] - 1]) ls.sort(reverse = True) for i in range(len(ls)): res += max(ls[i], res) print(res) ```
output
1
68,485
10
136,971
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman. Given the description of Appleman's cards. What is the maximum number of coins Toastman can get? Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n uppercase letters without spaces — the i-th letter describes the i-th card of the Appleman. Output Print a single integer – the answer to the problem. Examples Input 15 10 DZFDFZDFDDDDDDF Output 82 Input 6 4 YJSNPI Output 4 Note In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. Submitted Solution: ``` def spliter(): d = input() a = d.split() r = [] for i in a: k = int(i) r.append(k) return r n = spliter() k=input() lst=[] counter=[] count=1 maxcoin=0 noremain=n[1] count1=0 for i in range(n[0]): lst.append(k[i]) lst.sort() for i in range(1,n[0],1): if lst[i]==lst[i-1]: count+=1 count1+=1 else: counter.append(count) count=1 count1+=1 if i==n[0]-1: counter.append(count) counter.sort(reverse=True) if count1==0: counter.append(1) for i in counter: if i>noremain: maxcoin+=noremain*noremain break else: maxcoin+=i*i noremain-=i print(maxcoin) ```
instruction
0
68,504
10
137,008
Yes
output
1
68,504
10
137,009
Provide tags and a correct Python 3 solution for this coding contest problem. Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site. He has suggestions to work on n distinct projects. Mikhail has already evaluated that the participation in the i-th project will increase his experience by ai per day and bring bi dollars per day. As freelance work implies flexible working hours, Mikhail is free to stop working on one project at any time and start working on another project. Doing so, he receives the respective share of experience and money. Mikhail is only trying to become a cool programmer, so he is able to work only on one project at any moment of time. Find the real value, equal to the minimum number of days Mikhail needs to make his dream come true. For example, suppose Mikhail is suggested to work on three projects and a1 = 6, b1 = 2, a2 = 1, b2 = 3, a3 = 2, b3 = 6. Also, p = 20 and q = 20. In order to achieve his aims Mikhail has to work for 2.5 days on both first and third projects. Indeed, a1·2.5 + a2·0 + a3·2.5 = 6·2.5 + 1·0 + 2·2.5 = 20 and b1·2.5 + b2·0 + b3·2.5 = 2·2.5 + 3·0 + 6·2.5 = 20. Input The first line of the input contains three integers n, p and q (1 ≤ n ≤ 100 000, 1 ≤ p, q ≤ 1 000 000) — the number of projects and the required number of experience and money. Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1 000 000) — the daily increase in experience and daily income for working on the i-th project. Output Print a real value — the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 20 20 6 2 1 3 2 6 Output 5.000000000000000 Input 4 1 1 2 3 3 2 2 3 3 2 Output 0.400000000000000 Note First sample corresponds to the example in the problem statement.
instruction
0
68,570
10
137,140
Tags: geometry Correct Solution: ``` from fractions import Fraction def higher(x1, y1, x2, y2): if x1 == 0: if x2 == 0: return def min_days(p, q, pr): ma = max(a for a, b in pr) mb = max(b for a, b in pr) pr.sort(key=lambda t: (t[0], -t[1])) ch = [(0, mb)] for a, b in pr: if a == ch[-1][0]: continue while ( len(ch) >= 2 and ((b-ch[-2][1])*(ch[-1][0]-ch[-2][0]) >= (a-ch[-2][0])*(ch[-1][1]-ch[-2][1])) ): ch.pop() ch.append((a, b)) ch.append((ma, 0)) a1, b1 = None, None for a2, b2 in ch: if a1 is not None: d = (a2-a1)*q + (b1-b2)*p s = Fraction(b1*p-a1*q, d) if 0 <= s <= 1: return Fraction(d, a2*b1 - a1*b2) a1, b1 = a2, b2 if __name__ == '__main__': n, p, q = map(int, input().split()) pr = [] for _ in range(n): a, b = map(int, input().split()) pr.append((a, b)) print("{:.7f}".format(float(min_days(p, q, pr)))) ```
output
1
68,570
10
137,141
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site. He has suggestions to work on n distinct projects. Mikhail has already evaluated that the participation in the i-th project will increase his experience by ai per day and bring bi dollars per day. As freelance work implies flexible working hours, Mikhail is free to stop working on one project at any time and start working on another project. Doing so, he receives the respective share of experience and money. Mikhail is only trying to become a cool programmer, so he is able to work only on one project at any moment of time. Find the real value, equal to the minimum number of days Mikhail needs to make his dream come true. For example, suppose Mikhail is suggested to work on three projects and a1 = 6, b1 = 2, a2 = 1, b2 = 3, a3 = 2, b3 = 6. Also, p = 20 and q = 20. In order to achieve his aims Mikhail has to work for 2.5 days on both first and third projects. Indeed, a1·2.5 + a2·0 + a3·2.5 = 6·2.5 + 1·0 + 2·2.5 = 20 and b1·2.5 + b2·0 + b3·2.5 = 2·2.5 + 3·0 + 6·2.5 = 20. Input The first line of the input contains three integers n, p and q (1 ≤ n ≤ 100 000, 1 ≤ p, q ≤ 1 000 000) — the number of projects and the required number of experience and money. Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1 000 000) — the daily increase in experience and daily income for working on the i-th project. Output Print a real value — the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 20 20 6 2 1 3 2 6 Output 5.000000000000000 Input 4 1 1 2 3 3 2 2 3 3 2 Output 0.400000000000000 Note First sample corresponds to the example in the problem statement. Submitted Solution: ``` from fractions import Fraction def higher(x1, y1, x2, y2): if x1 == 0: if x2 == 0: return def min_days(p, q, pr): ma = max(a for a, b in pr) mb = max(b for a, b in pr) pr.sort(key=lambda t: (t[0], -t[1])) ch = [(0, mb)] for a, b in pr: if a == ch[-1][0]: continue while ( len(ch) >= 2 and ((b-ch[-2][1])*(ch[-1][1]-ch[-2][1]) >= (a-ch[-2][0])*(ch[-1][0]-ch[-2][0])) ): ch.pop() ch.append((a, b)) ch.append((ma, 0)) a1, b1 = None, None for a2, b2 in ch: if a1 is not None: d = (a2-a1)*q + (b1-b2)*p s = Fraction(b1*p-a1*q, d) if 0 <= s <= 1: return Fraction(d, a2*b1 - a1*b2) a1, b1 = a2, b2 if __name__ == '__main__': n, p, q = map(int, input().split()) pr = [] for _ in range(n): a, b = map(int, input().split()) pr.append((a, b)) print("{:.7f}".format(float(min_days(p, q, pr)))) ```
instruction
0
68,571
10
137,142
No
output
1
68,571
10
137,143
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site. He has suggestions to work on n distinct projects. Mikhail has already evaluated that the participation in the i-th project will increase his experience by ai per day and bring bi dollars per day. As freelance work implies flexible working hours, Mikhail is free to stop working on one project at any time and start working on another project. Doing so, he receives the respective share of experience and money. Mikhail is only trying to become a cool programmer, so he is able to work only on one project at any moment of time. Find the real value, equal to the minimum number of days Mikhail needs to make his dream come true. For example, suppose Mikhail is suggested to work on three projects and a1 = 6, b1 = 2, a2 = 1, b2 = 3, a3 = 2, b3 = 6. Also, p = 20 and q = 20. In order to achieve his aims Mikhail has to work for 2.5 days on both first and third projects. Indeed, a1·2.5 + a2·0 + a3·2.5 = 6·2.5 + 1·0 + 2·2.5 = 20 and b1·2.5 + b2·0 + b3·2.5 = 2·2.5 + 3·0 + 6·2.5 = 20. Input The first line of the input contains three integers n, p and q (1 ≤ n ≤ 100 000, 1 ≤ p, q ≤ 1 000 000) — the number of projects and the required number of experience and money. Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1 000 000) — the daily increase in experience and daily income for working on the i-th project. Output Print a real value — the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 20 20 6 2 1 3 2 6 Output 5.000000000000000 Input 4 1 1 2 3 3 2 2 3 3 2 Output 0.400000000000000 Note First sample corresponds to the example in the problem statement. Submitted Solution: ``` def higher(x1, y1, x2, y2): if x1 == 0: if x2 == 0: return def min_days(p, q, pr): ma = max(a for a, b in pr) mb = max(b for a, b in pr) pr.sort(key=lambda t: (t[0], -t[1])) ch = [(0, mb)] for a, b in pr: if a == ch[-1][0]: continue while ( len(ch) >= 2 and ((b-ch[-2][1])*(ch[-1][1]-ch[-2][1]) >= (a-ch[-2][0])*(ch[-1][0]-ch[-2][0])) ): ch.pop() ch.append((a, b)) ch.append((ma, 0)) a1, b1 = None, None for a2, b2 in ch: if a1 is not None: d = (a2-a1)*q + (b1-b2)*p if d != 0: s = (b1*p-a1*q)/float(d) if 0 <= s <= 1: return float(d)/(a2*b1 - a1*b2) a1, b1 = a2, b2 if __name__ == '__main__': n, p, q = map(int, input().split()) pr = [] for _ in range(n): a, b = map(int, input().split()) pr.append((a, b)) print(min_days(p, q, pr)) ```
instruction
0
68,572
10
137,144
No
output
1
68,572
10
137,145
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,708
10
139,416
"Correct Solution: ``` for i in range(1, 101): count = 0 temp = 0 SetCount = 0 try: str1 = input() list1 = str1.split(" ") str2 = input() list2 = str2.split(" ") list2.sort(key=int, reverse=True) for m in range(0, int(list1[0])): if (m+1) % int(list1[1]) == 0: SetCount = SetCount + 1 #elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]): # count = count + int(list2[m]) else: count = count + int(list2[m]) print(count) except: break ```
output
1
69,708
10
139,417
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,709
10
139,418
"Correct Solution: ``` # Aizu Problem 0227: Thanksgiving import sys, math, os, bisect # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") while True: n, m = [int(_) for _ in input().split()] if n == m == 0: break prices = sorted([int(_) for _ in input().split()], reverse=True) for i in range(m - 1, n, m): prices[i] = 0 print(sum(prices)) ```
output
1
69,709
10
139,419
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,710
10
139,420
"Correct Solution: ``` while 1: _,m=map(int, input().split()) if m==0:break p=sorted(map(int,input().split()),reverse=1) print(sum(p)-sum(p[m-1::m])) ```
output
1
69,710
10
139,421
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,711
10
139,422
"Correct Solution: ``` while True: n, m = map(int, input().split()) if n == 0: break price = sorted(map(int, input().split()), reverse=True) print(sum(price) - sum(price[m - 1::m])) ```
output
1
69,711
10
139,423
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,712
10
139,424
"Correct Solution: ``` while True: try: n,m = list(map(int,input().split())) if n == 0 and m == 0: break amari = n % m yasai = list(map(int,input().split())) yasai.sort() s = 0 if amari > 0: s = sum(yasai[0:amari]) i = 0 for y in yasai[amari:]: if i % m > 0: s += y i+=1 print(s) except: pass ```
output
1
69,712
10
139,425
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,713
10
139,426
"Correct Solution: ``` while True : n, m = map(int, input().split()) if n == 0 and m == 0 : break p = list(map(int, input().split())) p.sort(reverse=True) cst = 0 for i in range(n) : if (i+1) % m != 0 : cst += p[i] print(cst) ```
output
1
69,713
10
139,427
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,714
10
139,428
"Correct Solution: ``` # -*- coding: utf-8 -*- """ Thanksgiving http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0227 """ import sys def solve(n, m, prices): ans = 0 for i in range(0, n, m): t = prices[i:i+m] if len(t) == m: t[-1] = 0 ans += sum(t) return ans def main(args): while True: n, m = map(int, input().split()) if n == 0 and m == 0: break prices = sorted([int(p) for p in input().split()], reverse=True) ans = solve(n, m, prices) print(ans) if __name__ == '__main__': main(sys.argv[1:]) ```
output
1
69,714
10
139,429
Provide a correct Python 3 solution for this coding contest problem. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100
instruction
0
69,715
10
139,430
"Correct Solution: ``` while True: n, m = map(int, input().split()) if n == 0: break plst = sorted(list(map(int, input().split())), reverse=True) s = sum(plst) for i in range(m - 1, n, m): s -= plst[i] print(s) ```
output
1
69,715
10
139,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` while 1: qua,bag = input().split() qua = int(qua) bag = int(bag) if qua == 0: break price = list(map(int,input().split())) price.sort(reverse=True) for i in range(qua): if (i+1)%bag == 0: price[i]=-1 for i in range(qua//bag): price.remove(-1) pay = sum(price) print(pay) ```
instruction
0
69,716
10
139,432
Yes
output
1
69,716
10
139,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` # -*- coding: utf-8 -*- while 1: try: n, m = map(int, input().split()) if n == 0: break p = sorted(list(map(int, input().split()))) p.reverse() for i in range(m - 1, n, m): p[i] = 0 print(sum(p)) except: break ```
instruction
0
69,717
10
139,434
Yes
output
1
69,717
10
139,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` while 1: n, m = map(int, input().split()) if n == 0: break veg = list(map(int, input().split())) veg.sort(reverse=True) cnt = 0 ans = 0 while veg != []: cnt += 1 tmp = veg.pop(0) if cnt % m == 0: pass else: ans += tmp print(ans) ```
instruction
0
69,718
10
139,436
Yes
output
1
69,718
10
139,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` while True: try: n,m = list(map(int,input().split())) if n == 0 and m == 0: break amari = n % m yasai = list(map(int,input().split())) yasai.sort() s = 0 for i in range(n): if (i+1) % m > 0: s += yasai[-i-1] print(s) except: pass ```
instruction
0
69,719
10
139,438
Yes
output
1
69,719
10
139,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` for i in range(1, 101): count = 0 SetCount = 0 try: str1 = input() list1 = str1.split(" ") str2 = input() list2 = str2.split(" ") list2.sort(reverse=True) for m in range(0, int(list1[0])): if (m+1) % int(list1[1]) == 0: count = count + int(list2[m]) SetCount = SetCount + 1 elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]): count = count + int(list2[m]) print(count) except: break ```
instruction
0
69,720
10
139,440
No
output
1
69,720
10
139,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` while True: n,m = list(map(int,input().split())) if n == 0 and m == 0: break amari = n % m yasai = list(map(int,input().split())) yasai.sort() s = 0 if amari > 0: s = sum(yasai[0:amari]) i = 0 for y in yasai[amari:]: if i % m > 0: s += y i+=1 print(s) ```
instruction
0
69,721
10
139,442
No
output
1
69,721
10
139,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` for i in range(1, 101): count = 0 temp = 0 SetCount = 0 try: str1 = input() list1 = str1.split(" ") str2 = input() list2 = str2.split(" ") list2.sort(reverse=True) for m in range(0, int(list1[0])): if (m+1) % int(list1[1]) == 0: SetCount = SetCount + 1 #elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]): # count = count + int(list2[m]) else: count = count + int(list2[m]) print(count) except: break ```
instruction
0
69,722
10
139,444
No
output
1
69,722
10
139,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale. * Up to m vegetables can be packed in one bag. * For bags packed with m vegetables, the cheapest vegetables are free. * Bags with less than m vegetables are not eligible for the discount. The three went shopping at Seven Mart immediately. When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one. Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m p1 p2 ... pn The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable. The number of datasets does not exceed 100. Output Prints the minimum purchase price on one line for each input dataset. Example Input 4 2 50 40 100 80 7 3 400 300 100 700 200 600 500 0 0 Output 150 2100 Submitted Solution: ``` while True: a = input() print('a') ```
instruction
0
69,723
10
139,446
No
output
1
69,723
10
139,447
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,760
10
139,520
"Correct Solution: ``` while True: N,M = map(int,input().split()) if N == 0: break src = [] for i in range(N): d,p = map(int,input().split()) src.append((p,d)) money = M ans = 0 for p,d in sorted(src,reverse=True): guard = min(d,money) money -= guard ans += (d - guard) * p print(ans) ```
output
1
69,760
10
139,521
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,761
10
139,522
"Correct Solution: ``` da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] + da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = map(int,input().split()) k = sorted(k,key = lambda x: x[1],reverse = True) while j != i + 1: if da[1] > k[j][0]: da[1] -= k[j][0] j += 1 elif da[1] <= k[j][0] and da[1] > 0: su += (k[j][0] - da[1]) * k[j][1] da[1] = 0 j += 1 else: su += k[j][0] * k[j][1] j += 1 print(su) da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] ```
output
1
69,761
10
139,523
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,762
10
139,524
"Correct Solution: ``` #月曜五時間目 実践的プログラミング #ソートして襲われてはいけない時には、できるだけ護衛をつけるようにすることが最適であるので #ソートした後に左から貪欲に護衛をつけていって、お金がなくなったらそのまま何もしないと言う戦略で正解した。 #時間:15分 #Princess' Marriage #学んだこと:ソートして貪欲に考える #URL: https://onlinejudge.u-aizu.ac.jp/challenges/search/titles/2019 def solve(): N,M=map(int,input().split()) if N==0 and M==0: #終了条件 exit() else: d=[tuple(map(int,input().split())) for _ in range(N)] d.sort(key=lambda x:-x[1]) #襲われたやすいところから優先的に保護するためにソート cnt=0 money=M #money=所持金、cnt=襲われる期待値の累計和 for que in d: distance,value=que if money>=distance: money-=distance elif money<distance: cnt+=value*(distance-money) money=0 print(cnt) return solve() if __name__=="__main__": solve() ```
output
1
69,762
10
139,525
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,763
10
139,526
"Correct Solution: ``` while True: n,m=map(int,input().split()) matrix=[] if n==m==0: break else: for i in range(n): D,P=map(int,input().split()) matrix.append([D,P]) matrix.sort(key = lambda x:x[1],reverse=True) i=0 while m>0 and i<=n-1: pp=matrix[i][1] dd=matrix[i][0] if dd > m: matrix[i][0]=dd-m m=0 else: matrix[i][1]=0 m=m-dd i+=1 sum_matrix=[mm[0]*mm[1] for mm in matrix] print(sum(sum_matrix)) ```
output
1
69,763
10
139,527
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,764
10
139,528
"Correct Solution: ``` while True: n,m=map(int,input().split()) if n==0 and m==0: break pd=[list(map(int,input().split()))[::-1] for i in range(n)] pd.sort() pd.reverse() ans=0 for i in pd: if m>i[1]: m-=i[1] elif m>0: ans+=i[0]*(i[1]-m) m=0 else: ans+=i[0]*i[1] print(ans) ```
output
1
69,764
10
139,529
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,765
10
139,530
"Correct Solution: ``` while 1: N,M=map(int,input().split()) if not N and not M:break s=0 t=[] for _ in range(N): a,b=map(int,input().split()) s+=a*b t.extend([(b,a)]) for i in sorted(t)[::-1]: if i[1]<=M: s-=i[0]*i[1] M-=i[1] elif 0<M<i[1]: s-=M*i[0] M=0 break print(s) ```
output
1
69,765
10
139,531
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,766
10
139,532
"Correct Solution: ``` while True: n, m = (int(s) for s in input().split()) if not n: break sections = sorted(([int(s) for s in input().split()] for i in range(n)), key=lambda x: x[1], reverse=True) for i, (d, p) in enumerate(sections): m -= d if m <= 0: print(sum(s[0] * s[1] for s in sections[i+1:]) - p * m) break else: print(0) ```
output
1
69,766
10
139,533
Provide a correct Python 3 solution for this coding contest problem. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140
instruction
0
69,767
10
139,534
"Correct Solution: ``` b=True while b: n,m=map(int,input().split()) if n==0 and m==0: b=False exit else: l=[] for i in range(n): l1=list(map(int,input().split())) l1=l1[::-1] l.append(l1) l=sorted(l) l=l[::-1] s=0 for i in range(n): s+=l[i][0]*l[i][1] for i in range(n): if m-l[i][1]>=0: s-=l[i][0]*l[i][1] m-=l[i][1] else: s-=l[i][0]*m break print(s) ```
output
1
69,767
10
139,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` while True: n, m = map(int, input().split()) ex = [0] * 11 if n == 0: break for i in range(n): d, p = map(int, input().split()) ex[p] += d ex.reverse() for i in range(len(ex)): m -= ex[i] if m <= 0: ex[i] = abs(m) break else: ex[i] = 0 ex.reverse() ans = 0 for i in range(len(ex)): ans += ex[i] * i print(ans) ```
instruction
0
69,768
10
139,536
Yes
output
1
69,768
10
139,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` while True: N, M = map(int, input().split()) if N == 0 and M == 0: break travel = [list(map(int, input().split())) for _ in range(N)] travel.sort(reverse=True, key=lambda x:x[1]) for i, (d, _) in enumerate(travel): if M == 0: break travel[i][0] = max(0, d-M) M = max(0, M-d) print(sum(d*p for d, p in travel)) ```
instruction
0
69,769
10
139,538
Yes
output
1
69,769
10
139,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` while 1: N, M = map(int, input().split()) if N == M == 0: break S = [] for i in range(N): S.append(list(map(int, input().split()))) S.sort(key=lambda x:x[1], reverse=True) ans = 0 for d in S: if M >= d[0]: M -= d[0] else: d[0] -= M M = 0 ans += d[0] * d[1] print(ans) ```
instruction
0
69,770
10
139,540
Yes
output
1
69,770
10
139,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` readline = open(0).readline while 1: N, M = map(int, readline().split()) if N == M == 0: break Q = [] for i in range(N): d, p = map(int, readline().split()) Q.append((p, d)) Q.sort(reverse=1) ans = 0 for p, d in Q: if M >= 0: x = min(M, d) M -= x; d -= x ans += d * p print(ans) ```
instruction
0
69,771
10
139,542
Yes
output
1
69,771
10
139,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` while True: n, m = map(int, input().split()) if (n, m) == (0, 0): break dp = [list(map(int, input().split())) for i in range(n)] dp = sorted(dp, key=lambda kv:kv[1], reverse=True) r = 0 for d,p in dp: if m >= d: m -= d else: r += p*(d-m) m = 0 print(r ```
instruction
0
69,772
10
139,544
No
output
1
69,772
10
139,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` while True: N,M = map(int,input().strip().split(" ")) if [N,M] == [0,0]: break L = [] S = 0 #Sが襲われる回数の期待値 for i in range(N): l = list(map(int,input().strip().split(" "))) l.reverse() #ソートするとき具合がわるいので[P,D]の順に入れ替え L.append(l) S = S + l[0]*l[1] L.sort() j = N while M > 0: if M >= L[j-1][1]: S = S - L[j][0]*L[j][1] M = M - L[j][1] j = j - 1 else: S = S - L[j][0]*M M = M - L[j][1] print(S) ```
instruction
0
69,773
10
139,546
No
output
1
69,773
10
139,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)] ```
instruction
0
69,774
10
139,548
No
output
1
69,774
10
139,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Princess'Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, ... SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 ... in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N (1 ≤ N ≤ 10,000) and the budget M (0 ≤ M ≤ 1,000,000,000) of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di (1 ≤ Di ≤ 10,000) and the number of attacks when moving one unit distance between them Pi (0 ≤ Pi <= 10) ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 Example Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output 5 140 Submitted Solution: ``` da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] > 0 and j != i - 1: if da[1] >= k[j][0] and j != i: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)] ```
instruction
0
69,775
10
139,550
No
output
1
69,775
10
139,551
Provide a correct Python 3 solution for this coding contest problem. You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most $W$, that is capacity of the knapsack. * You can select at most $m_i$ items for $i$-th item. Find the maximum total value of items in the knapsack. Constraints * $1 \le N \le 50$ * $1 \le v_i \le 50$ * $1 \le w_i \le 10^9$ * $1 \le m_i \le 10^9$ * $1 \le W \le 10^9$ Input $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given. Output Print the maximum total values of the items in a line. Examples Input 4 8 4 3 2 2 1 1 1 2 4 3 2 2 Output 12 Input 2 100 1 1 100 2 1 50 Output 150 Input 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 Output 1166666666
instruction
0
69,787
10
139,574
"Correct Solution: ``` import sys from collections import deque readline = sys.stdin.readline write = sys.stdout.write def solve(): N, W = map(int, readline().split()) vs = [0]*N; ws = [0]*N; ms = [0]*N for i in range(N): vs[i], ws[i], ms[i] = map(int, readline().split()) V0 = max(vs) V = sum(v * min(V0, m) for v, m in zip(vs, ms)) dp = [W+1]*(V + 1) dp[0] = 0 for i in range(N): v = vs[i]; w = ws[i]; m = ms[i] c = min(V0, m) ms[i] -= c for k in range(v): que = deque() push = que.append popf = que.popleft; popb = que.pop for j in range((V-k)//v+1): a = dp[k + j*v] - j * w while que and a <= que[-1][1]: popb() push((j, a)) p, b = que[0] dp[k + j*v] = b + j * w if que and p <= j-c: popf() *I, = range(N) I.sort(key=lambda x: ws[x]/vs[x]) *S, = [(vs[i], ws[i], ms[i]) for i in I] ans = 0 def greedy(): yield 0 for i in range(V + 1): if dp[i] > W: continue rest = W - dp[i] r = i for v, w, m in S: m = min(m, rest // w) r += m * v rest -= m * w yield r write("%d\n" % max(greedy())) solve() ```
output
1
69,787
10
139,575
Provide a correct Python 3 solution for this coding contest problem. You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most $W$, that is capacity of the knapsack. * You can select at most $m_i$ items for $i$-th item. Find the maximum total value of items in the knapsack. Constraints * $1 \le N \le 50$ * $1 \le v_i \le 50$ * $1 \le w_i \le 10^9$ * $1 \le m_i \le 10^9$ * $1 \le W \le 10^9$ Input $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given. Output Print the maximum total values of the items in a line. Examples Input 4 8 4 3 2 2 1 1 1 2 4 3 2 2 Output 12 Input 2 100 1 1 100 2 1 50 Output 150 Input 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 Output 1166666666
instruction
0
69,788
10
139,576
"Correct Solution: ``` #!python3 iim = lambda: map(int, input().rstrip().split()) from heapq import heappush, heappop def resolve(): N, W = iim() S = [list(iim()) for i in range(N)] def f1(v, w, m): mm = [] i = 1 while i <= m: yield i m -= i i <<= 1 if m: yield m SS = list(sorted(((v*i, w*i) for v, w, m in S for i in f1(v, w, m)), key=lambda x: (x[0]/x[1], x[1]), reverse=True)) NN = len(SS) def ubound(v, w, i): for j in range(i, NN): vj, wj = SS[j] if w + wj > W: return (-v, -v - (W - w) * vj / wj) w += wj v += vj return (-v, -v) u0, u1 = ubound(0, 0, 0) um = u0 ans = 0 q = [] heappush(q, (u1, u0, 0, 0, 0)) #print(S, NN) #print(W, SS) while q: #print(q) uq0, uq1, vq, wq, i = heappop(q) if uq0 > um: break if i >= NN: continue vi, wi = SS[i] if wq + wi < W: heappush(q, (uq0, uq1, vq+vi, wq+wi, i + 1)) u0, u1 = ubound(vq, wq, i + 1) if u1 <= um: if u0 < um: um = u0 heappush(q, (u1, u0, vq, wq, i + 1)) print(-um) if __name__ == "__main__": resolve() ```
output
1
69,788
10
139,577
Provide a correct Python 3 solution for this coding contest problem. You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most $W$, that is capacity of the knapsack. * You can select at most $m_i$ items for $i$-th item. Find the maximum total value of items in the knapsack. Constraints * $1 \le N \le 50$ * $1 \le v_i \le 50$ * $1 \le w_i \le 10^9$ * $1 \le m_i \le 10^9$ * $1 \le W \le 10^9$ Input $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given. Output Print the maximum total values of the items in a line. Examples Input 4 8 4 3 2 2 1 1 1 2 4 3 2 2 Output 12 Input 2 100 1 1 100 2 1 50 Output 150 Input 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 Output 1166666666
instruction
0
69,789
10
139,578
"Correct Solution: ``` from typing import Tuple, List from heapq import heappush, heappop def max_value(max_weight: int, items: List[Tuple[int, int]]) -> float: def _cost(weight: int, value: int, i: int) -> Tuple[int, float]: # Use value as negative cost for j in range(i, n): v, w = items[j] if (weight + w > max_weight): return (-value, -value - (v / w) * (max_weight - weight)) weight += w value += v return (-value, -value * 1.0) n = len(items) items.sort(key=lambda x: x[1], reverse=True) items.sort(key=lambda x: x[0] / x[1], reverse=True) u, c = _cost(0, 0, 0) heap = [(c, u, 0, 0, 0)] maxcost = u while heap: cost, upper, weight, value, i = heappop(heap) if (cost > maxcost): break if (i < n): v, w = items[i] if (weight + w <= max_weight): heappush(heap, (cost, upper, weight + w, value + v, i + 1)) u, c = _cost(weight, value, i + 1) if (c < maxcost): if (u < maxcost): maxcost = u heappush(heap, (c, u, weight, value, i + 1)) return -maxcost if __name__ == '__main__': N, W = map(lambda x: int(x), input().split()) items: List[Tuple[int, int]] = [] for _ in range(N): v, w, m = map(lambda x: int(x), input().split()) for i in range(m.bit_length() - 1): h = 2 ** i m -= h items.append((v * h, w * h)) if m > 0: items.append((v * m, w * m)) print(max_value(W, items)) ```
output
1
69,789
10
139,579
Provide a correct Python 3 solution for this coding contest problem. You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most $W$, that is capacity of the knapsack. * You can select at most $m_i$ items for $i$-th item. Find the maximum total value of items in the knapsack. Constraints * $1 \le N \le 50$ * $1 \le v_i \le 50$ * $1 \le w_i \le 10^9$ * $1 \le m_i \le 10^9$ * $1 \le W \le 10^9$ Input $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given. Output Print the maximum total values of the items in a line. Examples Input 4 8 4 3 2 2 1 1 1 2 4 3 2 2 Output 12 Input 2 100 1 1 100 2 1 50 Output 150 Input 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 Output 1166666666
instruction
0
69,790
10
139,580
"Correct Solution: ``` def main(): from collections import deque from functools import cmp_to_key N, W, *A = map(int, open(0).read().split()) A = [list(a) for a in zip(*[iter(A)]*3)] Vmax = max(v for v, w, m in A) Vsum = 0 B = [] for i, (v, w, m) in enumerate(A): m_upper = min(m, Vmax-1) m_rest = m - m_upper A[i][2] = m_upper if m_rest: B.append((v, w, m_rest)) Vsum += v*m_upper INF = 1<<60 dp = [INF]*(Vsum+1) dp[0] = 0 for v, w, m in A: for ofs in range(v): q = deque() for j in range(Vsum+1): vj = ofs + j*v if vj > Vsum: break src = dp[vj] - j*w while q and q[-1][1] >= src: q.pop() q.append((j, src)) if q: ni, nw = q[0] dp[vj] = nw + j*w if ni == j - m: q.popleft() B.sort(key=cmp_to_key(lambda a, b: -1 if a[0]*b[1] > a[1]*b[0] else 1)) ans = 0 for V, d in enumerate(dp): if d > W: continue W_rest = W - d for v, w, m in B: n_item = min(m, W_rest//w) if n_item: V += n_item * v W_rest -= n_item * w if ans < V: ans = V print(ans) if __name__ == '__main__': main() ```
output
1
69,790
10
139,581
Provide a correct Python 3 solution for this coding contest problem. You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most $W$, that is capacity of the knapsack. * You can select at most $m_i$ items for $i$-th item. Find the maximum total value of items in the knapsack. Constraints * $1 \le N \le 50$ * $1 \le v_i \le 50$ * $1 \le w_i \le 10^9$ * $1 \le m_i \le 10^9$ * $1 \le W \le 10^9$ Input $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given. Output Print the maximum total values of the items in a line. Examples Input 4 8 4 3 2 2 1 1 1 2 4 3 2 2 Output 12 Input 2 100 1 1 100 2 1 50 Output 150 Input 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 Output 1166666666
instruction
0
69,791
10
139,582
"Correct Solution: ``` #!/usr/bin/env python3 # DPL_1_I: Combinatorial - Knapsack Problem with Limitations II from heapq import heappush, heappop def max_value(t, xs): def _cost(weight, value, i): for j in range(i, n): v, w = xs[j] if weight + w > t: return (-value, -value - (v/w)*(t-weight)) weight += w value += v return (-value, -value*1.0) n = len(xs) xs.sort(key=lambda x: x[1], reverse=True) xs.sort(key=lambda x: x[0]/x[1], reverse=True) u, c = _cost(0, 0, 0) heap = [(c, u, 0, 0, 0)] maxcost = u while heap: cost, upper, weight, value, i = heappop(heap) if cost > maxcost: break if i < n: v, w = xs[i] if weight+w <= t: heappush(heap, (cost, upper, weight+w, value+v, i+1)) u, c = _cost(weight, value, i+1) if c < maxcost: if u < maxcost: maxcost = u heappush(heap, (c, u, weight, value, i+1)) return -maxcost def run(): n, t = [int(i) for i in input().split()] xs = [] for _ in range(n): v, w, m = [int(i) for i in input().split()] for i in range(m.bit_length()-1): h = 2**i m -= h xs.append((v*h, w*h)) if m > 0: xs.append((v*m, w*m)) print(max_value(t, xs)) if __name__ == '__main__': run() ```
output
1
69,791
10
139,583
Provide tags and a correct Python 3 solution for this coding contest problem. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose. The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party. Input The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively. Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision. The United Party of Berland has the index 1. Output Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections. Examples Input 1 2 1 100 Output 0 Input 5 5 2 100 3 200 4 300 5 400 5 900 Output 500 Input 5 5 2 100 3 200 4 300 5 800 5 900 Output 600 Note In the first sample, The United Party wins the elections even without buying extra votes. In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes. In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
instruction
0
70,730
10
141,460
Tags: brute force, greedy Correct Solution: ``` from sys import stdin from collections import deque n,m = map(int, stdin.readline().split()) pc=dict() ph=dict() costs=[] class Cost: def __init__(self, id, cost, party) -> None: self.id=id self.cost=cost self.party=party self.removed=False for i in range(n): p, c = map(int,stdin.readline().split()) if p != 1: cost = Cost(i, c, p) costs.append(cost) pc.setdefault(p,[]).append(cost) ph[p] = ph.setdefault(p, 0) + 1 max_h=0 for p, pa in pc.items(): pa.sort(reverse=True, key=lambda x: x.cost) max_h = max(max_h, len(pa)) hp = [[] for _ in range(max_h+2)] for p, h in ph.items(): if p != 1: hp[h].append(p) ans=[0]*(max_h+2) costs.sort(key=lambda x:x.cost) dq = deque(costs) p_set = set() height_p1 = ph[1] if 1 in ph else 0 top_sum = 0 top_count = 0 for i in range(max_h+1, -1, -1): if len(costs) < i: ans[i] = float('inf') continue for p in hp[i]: p_set.add(p) for p in p_set: if len(pc[p]) > 0: min_cost = pc[p].pop() min_cost.removed=True top_sum += min_cost.cost top_count += 1 ans[i] += top_sum if height_p1+top_count < i: for j in range(i-height_p1-top_count): while dq[0].removed: dq.popleft() ans[i] += dq[0].cost dq.rotate(-1) dq.rotate(i-height_p1-top_count) print(min(ans)) ```
output
1
70,730
10
141,461
Provide tags and a correct Python 3 solution for this coding contest problem. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose. The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party. Input The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively. Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision. The United Party of Berland has the index 1. Output Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections. Examples Input 1 2 1 100 Output 0 Input 5 5 2 100 3 200 4 300 5 400 5 900 Output 500 Input 5 5 2 100 3 200 4 300 5 800 5 900 Output 600 Note In the first sample, The United Party wins the elections even without buying extra votes. In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes. In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
instruction
0
70,731
10
141,462
Tags: brute force, greedy Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase import io from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque from collections import Counter import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: math.gcd(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=0, func=lambda a, b: a+b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(11)] prime[0]=prime[1]=False #pp=[0]*10 def SieveOfEratosthenes(n=10): p = 2 c=0 while (p <= n): if (prime[p] == True): c+=1 for i in range(p, n+1, p): #pp[i]=1 prime[i] = False p += 1 #-----------------------------------DSU-------------------------------------------------- class DSU: def __init__(self, R, C): #R * C is the source, and isn't a grid square self.par = range(R*C + 1) self.rnk = [0] * (R*C + 1) self.sz = [1] * (R*C + 1) def find(self, x): if self.par[x] != x: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): xr, yr = self.find(x), self.find(y) if xr == yr: return if self.rnk[xr] < self.rnk[yr]: xr, yr = yr, xr if self.rnk[xr] == self.rnk[yr]: self.rnk[xr] += 1 self.par[yr] = xr self.sz[xr] += self.sz[yr] def size(self, x): return self.sz[self.find(x)] def top(self): # Size of component at ephemeral "source" node at index R*C, # minus 1 to not count the source itself in the size return self.size(len(self.sz) - 1) - 1 #---------------------------------Lazy Segment Tree-------------------------------------- # https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp class LazySegTree: def __init__(self, _op, _e, _mapping, _composition, _id, v): def set(p, x): assert 0 <= p < _n p += _size for i in range(_log, 0, -1): _push(p >> i) _d[p] = x for i in range(1, _log + 1): _update(p >> i) def get(p): assert 0 <= p < _n p += _size for i in range(_log, 0, -1): _push(p >> i) return _d[p] def prod(l, r): assert 0 <= l <= r <= _n if l == r: return _e l += _size r += _size for i in range(_log, 0, -1): if ((l >> i) << i) != l: _push(l >> i) if ((r >> i) << i) != r: _push(r >> i) sml = _e smr = _e while l < r: if l & 1: sml = _op(sml, _d[l]) l += 1 if r & 1: r -= 1 smr = _op(_d[r], smr) l >>= 1 r >>= 1 return _op(sml, smr) def apply(l, r, f): assert 0 <= l <= r <= _n if l == r: return l += _size r += _size for i in range(_log, 0, -1): if ((l >> i) << i) != l: _push(l >> i) if ((r >> i) << i) != r: _push((r - 1) >> i) l2 = l r2 = r while l < r: if l & 1: _all_apply(l, f) l += 1 if r & 1: r -= 1 _all_apply(r, f) l >>= 1 r >>= 1 l = l2 r = r2 for i in range(1, _log + 1): if ((l >> i) << i) != l: _update(l >> i) if ((r >> i) << i) != r: _update((r - 1) >> i) def _update(k): _d[k] = _op(_d[2 * k], _d[2 * k + 1]) def _all_apply(k, f): _d[k] = _mapping(f, _d[k]) if k < _size: _lz[k] = _composition(f, _lz[k]) def _push(k): _all_apply(2 * k, _lz[k]) _all_apply(2 * k + 1, _lz[k]) _lz[k] = _id _n = len(v) _log = _n.bit_length() _size = 1 << _log _d = [_e] * (2 * _size) _lz = [_id] * _size for i in range(_n): _d[_size + i] = v[i] for i in range(_size - 1, 0, -1): _update(i) self.set = set self.get = get self.prod = prod self.apply = apply MIL = 1 << 20 def makeNode(total, count): # Pack a pair into a float return (total * MIL) + count def getTotal(node): return math.floor(node / MIL) def getCount(node): return node - getTotal(node) * MIL nodeIdentity = makeNode(0.0, 0.0) def nodeOp(node1, node2): return node1 + node2 # Equivalent to the following: return makeNode( getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2) ) identityMapping = -1 def mapping(tag, node): if tag == identityMapping: return node # If assigned, new total is the number assigned times count count = getCount(node) return makeNode(tag * count, count) def composition(mapping1, mapping2): # If assigned multiple times, take first non-identity assignment return mapping1 if mapping1 != identityMapping else mapping2 #---------------------------------Pollard rho-------------------------------------------- def memodict(f): """memoization decorator for a function taking a single argument""" class memodict(dict): def __missing__(self, key): ret = self[key] = f(key) return ret return memodict().__getitem__ def pollard_rho(n): """returns a random factor of n""" if n & 1 == 0: return 2 if n % 3 == 0: return 3 s = ((n - 1) & (1 - n)).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): prev = p p = (p * p) % n if p == 1: return math.gcd(prev - 1, n) if p == n - 1: break else: for i in range(2, n): x, y = i, (i * i + 1) % n f = math.gcd(abs(x - y), n) while f == 1: x, y = (x * x + 1) % n, (y * y + 1) % n y = (y * y + 1) % n f = math.gcd(abs(x - y), n) if f != n: return f return n @memodict def prime_factors(n): """returns a Counter of the prime factorization of n""" if n <= 1: return Counter() f = pollard_rho(n) return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f) def distinct_factors(n): """returns a list of all distinct factors of n""" factors = [1] for p, exp in prime_factors(n).items(): factors += [p**i * factor for factor in factors for i in range(1, exp + 1)] return factors def all_factors(n): """returns a sorted list of all distinct factors of n""" small, large = [], [] for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1): if not n % i: small.append(i) large.append(n // i) if small[-1] == large[-1]: large.pop() large.reverse() small.extend(large) return small #---------------------------------Binary Search------------------------------------------ def binarySearch(arr, n, key): left = 0 right = n-1 mid = 0 res = n while (left <= right): mid = (right + left)//2 if (arr[mid] > key): res=mid right = mid-1 else: left = mid + 1 return res def binarySearch1(arr, n, key): left = 0 right = n-1 mid = 0 res=-1 while (left <= right): mid = (right + left)//2 if (arr[mid] > key): right = mid-1 else: res=mid left = mid + 1 return res #---------------------------------running code------------------------------------------ t=1 #t=int(input()) for _ in range (t): #n=int(input()) n,m=map(int,input().split()) #a=list(map(int,input().split())) #b=list(map(int,input().split())) #s=input() #n=len(s) res=10**13 votes=[[] for i in range (3001)] for i in range (n): p,cost=map(int,input().split()) votes[p].append(cost) for i in range (3001): votes[i].sort() for i in range (max(len(votes[1]),1),n+1): present=len(votes[1]) spare=[] ans=0 for j in range (2,3001): ind=0 if len(votes[j])>=i: for k in range (len(votes[j])-i+1): ans+=votes[j][k] present+=1 ind=len(votes[j])-i+1 for k in range (ind,len(votes[j])): spare.append(votes[j][k]) #print(i,spare,present,ans) if present>i: continue spare.sort() for j in range (min(i-present,len(spare))): ans+=spare[j] present+=1 if present!=i: continue res=min(res,ans) #print(i,ans) print(res) ```
output
1
70,731
10
141,463
Provide tags and a correct Python 3 solution for this coding contest problem. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose. The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party. Input The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively. Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision. The United Party of Berland has the index 1. Output Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections. Examples Input 1 2 1 100 Output 0 Input 5 5 2 100 3 200 4 300 5 400 5 900 Output 500 Input 5 5 2 100 3 200 4 300 5 800 5 900 Output 600 Note In the first sample, The United Party wins the elections even without buying extra votes. In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes. In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
instruction
0
70,732
10
141,464
Tags: brute force, greedy Correct Solution: ``` n, m = map(int, input().split()) pc = [(0, 0) for _ in range(n)] party_votes = [0 for _ in range(m)] for i in range(n): p, c = map(int, input().split()) pc[i] = (p - 1, c) party_votes[p - 1] += 1 pc.sort(key=lambda x: x[1]) min_cost = 10**20 for votes in range(n + 1): _party_votes = party_votes[:] dangerous = list(map(lambda party: _party_votes[party] >= votes, range(0, m))) used = list(map(lambda i: pc[i][0] == 0, range(n))) cur_cost = 0 for i in range(n): if dangerous[pc[i][0]] and pc[i][0] != 0: cur_cost += pc[i][1] _party_votes[0] += 1 _party_votes[pc[i][0]] -= 1 dangerous[pc[i][0]] = _party_votes[pc[i][0]] >= votes used[i] = True for i in range(n): if _party_votes[0] >= votes: break if not used[i]: _party_votes[0] += 1 cur_cost += pc[i][1] min_cost = min(min_cost, cur_cost) print(min_cost) ```
output
1
70,732
10
141,465
Provide tags and a correct Python 3 solution for this coding contest problem. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose. The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party. Input The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively. Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision. The United Party of Berland has the index 1. Output Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections. Examples Input 1 2 1 100 Output 0 Input 5 5 2 100 3 200 4 300 5 400 5 900 Output 500 Input 5 5 2 100 3 200 4 300 5 800 5 900 Output 600 Note In the first sample, The United Party wins the elections even without buying extra votes. In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes. In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
instruction
0
70,733
10
141,466
Tags: brute force, greedy Correct Solution: ``` from sys import stdin n,m = map(int, stdin.readline().split()) pc=dict() ph=dict() prices = [] for i in range(n): p,c=map(int,stdin.readline().split()) if p != 1: prices.append(c) pc.setdefault(p,[]).append(len(prices)-1) ph[p] = ph.setdefault(p, 0) + 1 max_h=0 for p, pa in pc.items(): pa.sort(reverse=True, key=lambda x: prices[x]) max_h = max(max_h, len(pa)) hp = [[] for _ in range(max_h+2)] for p, h in ph.items(): if p != 1: hp[h].append(p) ans=[0]*(max_h+2) sprices_ind = sorted(range(len(prices)), key=lambda x: prices[x]) p_set = set() height_p1 = ph[1] if 1 in ph else 0 top_sum = 0 top_count = 0 for i in range(max_h+1, -1, -1): if len(prices) < i: ans[i] = float('inf') continue for p in hp[i]: p_set.add(p) for p in p_set: if len(pc[p]) > 0: top_ind = pc[p].pop() c = prices[top_ind] prices[top_ind] = -1 top_sum += c top_count += 1 ans[i] += top_sum if height_p1+top_count < i: k = 0 for j in range(i-height_p1-top_count): while prices[sprices_ind[k]] == -1: k += 1 ans[i] += prices[sprices_ind[k]] k += 1 print(min(ans)) ```
output
1
70,733
10
141,467
Provide tags and a correct Python 3 solution for this coding contest problem. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose. The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party. Input The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively. Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision. The United Party of Berland has the index 1. Output Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections. Examples Input 1 2 1 100 Output 0 Input 5 5 2 100 3 200 4 300 5 400 5 900 Output 500 Input 5 5 2 100 3 200 4 300 5 800 5 900 Output 600 Note In the first sample, The United Party wins the elections even without buying extra votes. In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes. In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
instruction
0
70,734
10
141,468
Tags: brute force, greedy Correct Solution: ``` import sys import os def solve(m, candidates): n = len(candidates) candidates.sort(key=lambda x: x[1]) party = dict() granted = 0 for i in range(len(candidates)): p = candidates[i][0] c = candidates[i][1] if p == 1: granted += 1 continue if p in party: party[p].append((i, c)) else: party[p] = [(i, c)] result = None for t in range(1, n // 2 + 2): total = 0 chosen = set() for k, v in party.items(): if len(v) >= t: for i in range(len(v) + 1 - t): chosen.add(v[i][0]) total += v[i][1] for i in range(n): if len(chosen) + granted >= t: break if i not in chosen and candidates[i][0] != 1: chosen.add(i) total += candidates[i][1] if result is None: result = total else: result = min(result, total) return result def main(): n, m = map(int, input().split()) candidates = [] for i in range(n): p, c = map(int, input().split()) candidates.append((p, c)) print(solve(m, candidates)) if __name__ == '__main__': main() ```
output
1
70,734
10
141,469
Provide tags and a correct Python 3 solution for this coding contest problem. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose. The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party. Input The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively. Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision. The United Party of Berland has the index 1. Output Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections. Examples Input 1 2 1 100 Output 0 Input 5 5 2 100 3 200 4 300 5 400 5 900 Output 500 Input 5 5 2 100 3 200 4 300 5 800 5 900 Output 600 Note In the first sample, The United Party wins the elections even without buying extra votes. In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes. In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
instruction
0
70,735
10
141,470
Tags: brute force, greedy Correct Solution: ``` import sys f=sys.stdin out=sys.stdout n,m=map(int,f.readline().rstrip('\r\n').split()) cos={} cost=[] nvot=[0 for i in range(m+1)] party=[[] for i in range(m+1)] for i in range(n): p,c=map(int,f.readline().rstrip('\r\n').split()) if p!=1: if c in cos: cos[c]+=1 else: cos[c]=1 cost.append(c) party[p].append(c) nvot[p]+=1 cost.sort() for i in party: i.sort() mi=float('inf') for x in range(1,n+1): dcos=dict(cos) tmp=0 vot=nvot[1] for j in range(2,m+1): if nvot[j]>=x: for k in range(nvot[j]-x+1): vot+=1 tmp+=party[j][k] dcos[party[j][k]]-=1 j=0 while vot<x: if(dcos[cost[j]]>0): dcos[cost[j]]-=1 tmp+=cost[j] vot+=1 j+=1 #print(tmp) mi=min(mi,tmp) out.write(str(mi)+"\n") ```
output
1
70,735
10
141,471