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
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. 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. Find the maximum total value of items in the knapsack. Constraints * 1 ≀ N ≀ 40 * 1 ≀ vi ≀ 1015 * 1 ≀ wi ≀ 1015 * 1 ≀ W ≀ 1015 Input N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following N lines, the value and weight of the i-th item are given. Output Print the maximum total values of the items in a line. Examples Input 4 5 4 2 5 2 2 1 8 3 Output 13 Input 2 20 5 9 4 10 Output 9 Submitted Solution: ``` N,W = map(int,input().split()) v = [0]*N;w = [0]*N for i in range(N): v[i],w[i] = map(int,input().split()) value = [0 for i in range(W+1)] for i in range(N): for j in range(W,W/2,-1): if j<w[i]: value[j] = value[j] else: value[j] = max(value[j],value[j-w[i]]+v[i]) print(value[W]) ```
instruction
0
15,045
10
30,090
No
output
1
15,045
10
30,091
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,074
10
30,148
Tags: brute force Correct Solution: ``` n,m=map(int,input().split()) prices=list(map(int,input().split())) match=[[False for _ in range(n+1)]for j in range(n+1)] for i in range(m): v,u=map(int,input().split()) match[u][v]=match[v][u]=True t=-1 for i in range(1,n+1): for j in range(i+1,n+1): if not match[i][j]:continue for k in range(j+1,n+1): if match[k][i] and match[j][k]: price=prices[i-1]+prices[j-1]+prices[k-1] if t==-1 or price<t: t=price print(t) ```
output
1
15,074
10
30,149
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,075
10
30,150
Tags: brute force Correct Solution: ``` n,m=map(int,input().split()) pr=list(map(int,input().split())) g=[[0]*(n+1) for i in range(n+1)] for i in range(m): a,b=map(int,input().split()) g[a][b]=g[b][a]=1 ans=float('inf') for i in range(1,n+1): for j in range(i+1,n+1): for k in range(j+1,n+1): if(g[i][j]==g[i][k]==g[k][j]==1): ans=min(ans,pr[i-1]+pr[j-1]+pr[k-1]) if(ans==float('inf')):ans=-1 print(ans) ```
output
1
15,075
10
30,151
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,076
10
30,152
Tags: brute force Correct Solution: ``` ans = float('inf') N, M = map(int, input().split()) price = [0] + list(map(int, input().split())) match = [set() for _ in range(N+1)] for _ in range(M): a,b = map(int, input().split()) match[a].add(b) match[b].add(a) for i in range(1,N+1): for j in range(i+1, N+1): for k in range(j+1, N+1): mi = i in match[j] and i in match[k] mj = j in match[i] and j in match[k] mk = k in match[i] and k in match[j] if mi and mj and mk: p = price[i] + price[j] + price[k] ans = min(ans, p) print(-1 if ans == float('inf') else ans) ```
output
1
15,076
10
30,153
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,077
10
30,154
Tags: brute force Correct Solution: ``` I = lambda: map(int, input().split()) n, m = I() A = list(I()) C = set() for i in range(m): x, y = sorted(I()) C.add((x-1,y-1)) print(min((A[i]+A[j]+A[k] for i in range(n) for j in range(i) for k in range(j) if {(j,i),(k,i),(k,j)} <= C), default=-1)) ```
output
1
15,077
10
30,155
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,078
10
30,156
Tags: brute force Correct Solution: ``` from math import * class graph: # initialize graph def __init__(self, gdict=None): if gdict is None: gdict = dict({}) self.gdict = gdict # get edges def edges(self): return self.find_edges() # find edges def find_edges(self): edges = [] for node in self.gdict: for nxNode in self.gdict[node]: if {nxNode, node} not in edges: edges.append({node, nxNode}) return edges # Get verticies def get_vertices(self): return list(self.gdict.keys()) # add vertix def add_vertix(self, node): if node not in self.gdict: self.gdict[node] = [] # add edge def add_edge(self, edge): edge = set(edge) (node1, node2) = edge if node1 in self.gdict: self.gdict[node1].append(node2) else: self.gdict[node1] = [node2] if node2 in self.gdict: self.gdict[node2].append(node1) else: self.gdict[node2] = [node1] def inp(): return map(int, input().split()) def arr_inp(): return [int(x) for x in input().split()] n, m = inp() a = arr_inp() g = graph() cost = inf for i in range(m): u, v = inp() g.add_edge((u, v)) if (i > 1): for key in g.gdict: if (u in g.gdict[key] and v in g.gdict[key]): cost = min(cost, a[u - 1] + a[v - 1] + a[int(key) - 1]) if (cost == inf): print(-1) else: print(cost) ```
output
1
15,078
10
30,157
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,079
10
30,158
Tags: brute force Correct Solution: ``` import math import queue from itertools import permutations n,m= map(int,input().split()) upper=3000003 ans=upper a=[] for i in range(0,n+1): a.append([]) for j in range(0,n+1): a[i].append(0) v=[int(cost) for cost in input().split()] v=[0]+v for i in range(0,m): p,q=map(int,input().split()) a[p][q]=1 a[q][p]=1 for i in range(1,n+1): for j in range(1,n+1): for k in range(1,n+1): if a[i][j]==1 and a[j][k]==1 and a[k][i]==1: current=v[i]+v[j]+v[k] if current<ans: ans=current if ans==upper: ans=-1 print(ans) ```
output
1
15,079
10
30,159
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,080
10
30,160
Tags: brute force Correct Solution: ``` n, m = map(int, input().split()) prices = list(map(int, input().split())) matches = [[]] * m matches = [[0 for _ in range(n)] for _ in range(n)] for _ in range(m): a, b = map(lambda x: int(x) - 1, input().split()) matches[a][b] = 1 matches[b][a] = 1 MAX_MIN_COST = 3 * 10**6 min_cost = MAX_MIN_COST + 1 for i in range(n): for j in range(i+1, n): for k in range(j+1, n): if matches[i][j] == 1 and \ matches[i][k] == 1 and \ matches[j][k] == 1: min_cost = min([min_cost, prices[i] + \ prices[j] + \ prices[k]]) if min_cost == MAX_MIN_COST + 1: print("-1") else: print(min_cost) ```
output
1
15,080
10
30,161
Provide tags and a correct Python 3 solution for this coding contest problem. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
instruction
0
15,081
10
30,162
Tags: brute force Correct Solution: ``` #!/usr/bin/env python3 import sys srci = sys.stdin n, m = map(int, srci.readline().rstrip().split()) prices = list(map(int, srci.readline().rstrip().split())) match = [[False for i in range(n+1)] for i in range(n+1)] for i in range(m): u, v = map(int, srci.readline().rstrip().split()) match[u][v] = match[v][u] = True mn = -1 for i in range(1, n+1): for j in range(i+1, n+1): if not match[i][j]: continue for k in range(j+1, n+1): if match[j][k] and match[k][i]: t = prices[i-1] + prices[j-1] + prices[k-1] if mn == -1 or t < mn: mn = t print(mn) ```
output
1
15,081
10
30,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` n, m = map(int, input().split()) c = [0] + list(map(int, input().split())) p = [[] for i in range(n + 1)] for i in range(m): a, b = map(int, input().split()) p[a].append(b) p[b].append(a) p = [(c[i], set(q), i) for i, q in enumerate(p)] p.sort() s = 3000001 for i in range(1, n - 1): if 3 * p[i][0] >= s: break for j in range(i + 1, n): if p[i][0] + 2 * p[j][0] >= s: break if not p[j][2] in p[i][1]: continue for k in range(j + 1, n + 1): if p[i][0] + p[j][0] + p[k][0] >= s: break if p[k][2] in p[i][1] and p[k][2] in p[j][1]: s = p[i][0] + p[j][0] + p[k][0] break print(s if s < 3000001 else -1) ```
instruction
0
15,082
10
30,164
Yes
output
1
15,082
10
30,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` import itertools import math import time def timer(f): def tmp(*args, **kwargs): t = time.time() res = f(*args, **kwargs) print("ВрСмя выполнСния Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ: %f" % (time.time()-t)) return res return tmp #n = int(input()) n, m = map(int, input().split(' ')) array = list(map(int, input().split(' '))) matrix = [[0 for j in range(n)] for i in range(n)] for i in range(m): a, b = map(int, input().split(' ')) a-=1 b-=1 matrix[a][b] = 1 matrix[b][a] = 1 price = 100000000000000 u = 0; uu = 0; uuu = 0; for i in range(n): for j in range(n): for k in range(n): if i!=j and j!=k and i!=k: if matrix[i][j]==1 and matrix[i][k]==1 and matrix[j][k]==1: cp = array[i]+array[j]+array[k] if cp<price: price = cp u = i uu = j uuu = k else: #print(i, j, k) pass if price == 100000000000000: print(-1) else: print(price) ```
instruction
0
15,083
10
30,166
Yes
output
1
15,083
10
30,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=[[0 for i in range(n)] for i in range(n)] for i in range(m): u,v=list(map(int,input().split())) b[u-1][v-1]=1 b[v-1][u-1]=1 c=-1 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if b[i][j] and b[j][k] and b[i][k] and (c==-1 or a[i]+a[j]+a[k]<c): c=a[i]+a[j]+a[k] print(c) ```
instruction
0
15,084
10
30,168
Yes
output
1
15,084
10
30,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` temp_numbers = list(map(int,input().split())) n, m = temp_numbers[0], temp_numbers[1] cost = list(map(int,input().split())) min_cost = 3.1*10**6 adj = [[0 for i in range(n)] for j in range(n)] for i in range(m): temp_input = list(map(int,input().split())) adj[temp_input[0]-1][temp_input[1]-1] = 1 adj[temp_input[1]-1][temp_input[0]-1] = 1 for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): if adj[i][j] == adj[j][k] == adj[k][i] == 1 : min_cost = min(min_cost, cost[i] + cost[j] + cost[k]) if min_cost <= 3*10**6: print(min_cost) else: print(-1) ```
instruction
0
15,085
10
30,170
Yes
output
1
15,085
10
30,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` #CF-650 (DIV-3) '''test=int(input()) for i in range(test): b=input() ans="" if len(b)==2: ans=b else: ans+=b[0] j=1 while j<len(b)-1: ans+=b[j] j+=2 ans+=b[-1] print(ans) ''' '''test=int(input()) for i in range(test): n=int(input()) arr=[int(i) for i in input().split()] type1=0 type2=0 for i in range(n): if i%2==0 and arr[i]%2==1: type1+=1 elif i%2==1 and arr[i]%2==0: type2+=1 if type1!=type2: print(-1) else: print(type1)''' '''test=int(input()) for i in range(test): n,k=[int(i) for i in input().split()] binary=input() suff=[float("inf")]*(n) suff[-1]=0 if binary[-1]=="1" else float("inf") for j in range(len(binary)-2,-1,-1): if binary[j]=="1": suff[j]=0 else: suff[j]=1+suff[j+1] last=-1 ans=0 for i in range(len(binary)): if binary[i]=="0": if last!=-1: if i-last>k and suff[i]>k: ans+=1 last=i elif suff[i]>k: ans+=1 last=i else: last=i print(ans)''' '''test=int(input()) for i in range(test): import heapq s=input() m=int(input()) arr=[int(i) for i in input().split()] s=sorted("".join([i for i in s])) heap=[] for i in range(m): heapq.heappush(heap,(arr[i],i)) ans=[""]*(m) t=0 while heap: a,b=heapq.heappop(heap) while True: sum_=0 for i in range(m): if ans[i]!="": sum_+=abs(b-i) if sum_==a: break else: t+=1 ans[b]=s[t] print("".join(ans))''' #CODEFORCES GLOBAL ROUND '''test=int(input()) for i in range(test): a,b,n=[int(i) for i in input().split()] ans=0 while a<=n and b<=n: if a>=b: b+=a else: a+=b ans+=1 print(ans)''' '''k=int(input()) item="codeforces" print(item,end="") printable=10**(3) s="s"*(10**(3)) k-=1 while k>printable: print(s,end="") k-=printable print("s"*(k))''' # codeforces 651 DIV-2 '''test=int(input()) for i in range(test): n=int(input()) l=1 r=n ans=1 while l<=r: mid=l+(r-l)//2 if mid*2<=n: ans=mid l=mid+1 else: r=mid-1 print(ans) ''' '''test=int(input()) for i in range(test): n=int(input()) if n==1: print("FastestFinger") elif n%2: print("Ashishgup") elif n==2: print("Ashishgup") elif n&(n-1)==0: print("FastestFinger") else: res=[] i=2 while i**2<=n: cnt=0 while n%i==0: n=n//i cnt+=1 res.append((i,cnt)) i+=1 #print(i,n) if n>1: res.append((n,1)) prime=0 alpha=0 for i in res: if i[0]!=2: prime+=i[1] else: alpha=i[1] if alpha>1: print("Ashishgup") elif prime>=2: print("Ashishgup") else: print("FastestFinger")''' '''n,k=[int(i) for i in input().split()] arr=[int(i) for i in input().split()] ''' '''test=int(input()) for i in range(test): n=int(input()) arr=[int(i) for i in input().split()] eve=[] odd=[] if n==2: print(3,4,sep=" ") else: for i in range(len(arr)): if arr[i]%2: odd.append(i) else: eve.append(i) if len(odd)%2: odd.pop() eve.pop() else: if len(eve)>=2: eve.pop() eve.pop() else: odd.pop() odd.pop() j=0 while j<len(odd): print(odd[j]+1,odd[j+1]+1) j+=2 k=0 while k<len(eve): print(eve[k]+1,eve[k+1]+1) k+=2''' '''n,k=[int(i) for i in input().split()] arr=[int(i) for i in input().split()] def check(x,p): ans=0 for i in range(len(arr)): if (not p): ans+=1 p^=1 else: if arr[i]<=x: ans+=1 p^=1 return ans>=k l=1 r=10**9 res=0 while l<=r: mid=l+(r-l)//2 if check(mid,0) or check(mid,1): res=mid r=mid-1 else: l=mid+1 print(res) ''' #ATCODER BEGINNER # CODEFORCESDIV-2 ROUND 652 '''test=int(input()) for i in range(test): n=int(input()) if n==3: print("NO") elif (n-2)%2: print("NO") else: if ((n-2)//2)%2: print("YES") else: print("NO")''' '''test=int(input()) for i in range(test): n=int(input()) s=input() last=len(s) res=s[0] for i in range(len(s)-1,-1,-1): if s[i]=="0": last=i break if last==len(s): print(s) else: j=-1 k=0 while k<=last and s[k]!="1": j+=1 k+=1 if j==last: print(s) else: print(s[:j+1]+s[last:]) else: for i in range(1,last): if s[i]=="0" and res[-1]!="1": res+=s[i] elif s[i]=="1": res+=s[i] i=len(res)-1 while i>=0 and res[i]!="0": i-=1 print(res[:i+1]+s[last:])''' '''test=int(input()) from collections import defaultdict for i in range(test): n,k=[int(i) for i in input().split()] arr=[int(i) for i in input().split()] w=[int(i) for i in input().split()] ans=[[]]*(k) if n==k: print(2*sum(arr)) else: cnt=defaultdict(int) for i in arr: cnt[i]+=1 #print(cnt) res=sorted(cnt.items(),key=lambda x:x[0],reverse=True) w.sort() for i in range(len(res)): for j in range(res[i][1]): for k in range(len(w)): if w[k]>0: ans[k].append(res[i][0]) w[k]-=1 t=0 for p in ans: t+=max(p)+min(p) print(t) ''' '''n=int(input()) arr=[int(i) for i in input().split()] dp=[1]*(max(arr)+1) ele=set() for i in arr: ele.add(i) for i in range(2,max(arr)+1): if i in ele and dp[i]: j=2 while i*j<=max(arr): if i*j in ele: dp[i*j]=0 j+=1 cnt=0 for i in range(2,len(dp)): if i in ele and dp[i]: cnt+=1 if len(ele)==1: print(0) else: print(cnt)''' #Practice DIV2-c '''n,s=[int(i) for i in input().split()] def pos(n,s): if s>=0 and s<=9*n: return True return False if n==1: if s>9: print(-1,-1) else: print(s,s) elif s==0: if n==1: print(0,0) else: print(-1,-1) else: temp=s minn="" for i in range(n): for j in range(10): if (i>0 or j>0 or (n==1 and j==0)) and pos(n-i-1,s-j): minn+=str(j) s-=j break maxx="" for i in range(n): for j in range(9,-1,-1): if (i>0 or j>0 or (n==1 and j==0)) and pos(n-i-1,temp-j): maxx+=str(j) temp-=j break if minn and maxx: print(minn,maxx) else: print(-1,-1)''' n,m=[int(i) for i in input().split()] price=[int(i) for i in input().split()] from collections import defaultdict graph=defaultdict(list) for i in range(m): p,c=[int(i) for i in input().split()] graph[p].append(c) graph[c].append(p) visited=[0]*(n+1) pushed=[0]*(n+1) minn=[] def bfs(p): stack=[] stack.append(p) while stack: start=stack.pop(0) visited[start]=1 for j in graph[start]: if not visited[j]: visited[j]=1 stack.append(j) pushed[j]=start else: if pushed[j]==pushed[start]: minn.append(price[j-1]+price[start-1]+price[pushed[j]-1]) bfs(1) print(pushed) if not minn: print(-1) else: print(min(minn)) ```
instruction
0
15,086
10
30,172
No
output
1
15,086
10
30,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` n,m=map(int,input().split()) from collections import defaultdict d=defaultdict(list) ans=10**9 l=[int(i) for i in input().split()] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 d[a].append(b) for i in range(n): for j in range(i+1,n): for k in range(j+1): if j in d[i] and k in d[j] and i in d[k]: ans=min(ans,l[i]+l[j]+l[k]) print(ans if ans!=10**9 else -1) ```
instruction
0
15,087
10
30,174
No
output
1
15,087
10
30,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` a,b=[int(i) for i in input().split()] c=[int(i) for i in input().split()] l=[] l1=[] for i in range(b): d,e=[int(i) for i in input().split()] l.append(d) l.append(e) z=[] for i in range(0,len(l)-5,2): z=l[i:i+6] if(len(z)==6 and len(set(z))==3): l1.append((c[i]+c[i+1]+c[i+2])) if(len(l1)==0): print(-1) else: print(min(l1)) ```
instruction
0
15,088
10
30,176
No
output
1
15,088
10
30,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input The first input file line contains integers n and m β€” the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>). Next line contains n integers ai (1 ≀ ai ≀ 106) β€” the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different. Output Print the only number β€” the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Examples Input 3 3 1 2 3 1 2 2 3 3 1 Output 6 Input 3 2 2 3 4 2 3 2 1 Output -1 Input 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Output -1 Note In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way β€” to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. Submitted Solution: ``` n, m = map(int, input().split()) c = [0] + list(map(int, input().split())) p = [[] for i in range(n + 1)] for i in range(m): a, b = map(int, input().split()) p[a].append(b) p[b].append(a) p = [(c[i], set(q)) for i, q in enumerate(p)] s = 3000001 for i in range(1, n - 1): if 3 * p[i][0] >= s: break for j in range(i + 1, n): if p[i][0] + 2 * p[j][0] >= s: break if not j in p[i][1]: continue for k in range(j + 1, n + 1): if p[i][0] + p[j][0] + p[k][0] >= s: break if k in p[i][1] and k in p[j][1]: s = p[i][0] + p[j][0] + p[k][0] break print(s if s < 3000001 else -1) ```
instruction
0
15,089
10
30,178
No
output
1
15,089
10
30,179
Provide a correct Python 3 solution for this coding contest problem. A: four tea problem Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed] There are N players participating in the contest, so I would like to prepare tea for this number of people. There are four types of tea packages, A, B, C, and D, all of which are the same variety but have different contents. For a package X, the price of one package is p_X yen, and it is known that if you buy one, you can make t_X cups of tea. Find the minimum amount needed to make tea for N people. You may have a package that you don't buy at all, and you don't have to buy a package for just N people (if you can make more than N people). Input format The input is given in the following format. N p_A p_B p_C p_D t_A t_B t_C t_D * The first line gives the number of players participating in the contest. * In the second line, the prices of tea in packages A, B, C and D are given separated by blanks. * The third line gives the number of cups of tea that can be made from packages A, B, C, and D, separated by blanks. Constraint * 1 \ leq N \ leq 100 * 1 \ leq p_X \ leq 100 * 1 \ leq t_X \ leq 100 * All inputs are given as integers. Output format Output the minimum amount required to make tea for N people in one line. Input example 1 Ten 1 2 3 4 1 2 4 8 Output example 1 6 * It's best to buy one package B and one D. Input example 2 Five 2 9 9 8 1 4 5 100 Output example 2 8 * You will have 20 times more tea than you need, but buying one Package D is the cheapest way to get more than 5 cups of tea. Input example 3 twenty four 2 3 4 7 7 9 11 20 Output example 3 8 * It's best to buy two packages A and one C. It may not be possible to make just enough tea for the number of people as in this case. Example Input 10 1 2 3 4 1 2 4 8 Output 6
instruction
0
15,905
10
31,810
"Correct Solution: ``` # -*- coding: utf-8 -*- import sys from operator import itemgetter from fractions import gcd from math import ceil, floor, sqrt from copy import deepcopy from collections import Counter, deque import heapq from functools import reduce # local only # if not __debug__: # fin = open('in_1.txt', 'r') # sys.stdin = fin # local only sys.setrecursionlimit(200000) input = sys.stdin.readline def ii(): return int(input()) def mi(): return map(int, input().rstrip().split()) def lmi(): return list(map(int, input().rstrip().split())) def li(): return list(input().rstrip()) def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None def exit(*arg): print(*arg); sys.exit() # template def main(): N = ii() p = lmi() t = lmi() n = len(p) v = [(i, p[i] / t[i]) for i in range(n)] v.sort(key=itemgetter(1)) m = v[0][0] # print(v) ans = ceil(N / t[m]) * p[m] for i in range(4): if i != m: # print(ceil((N - t[i]) // t[m])) ans = min(ans, ceil((N - t[i]) / t[m]) * p[m] + p[i]) # print(ans) print(ans) if __name__ == '__main__': main() ```
output
1
15,905
10
31,811
Provide a correct Python 3 solution for this coding contest problem. A: four tea problem Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed] There are N players participating in the contest, so I would like to prepare tea for this number of people. There are four types of tea packages, A, B, C, and D, all of which are the same variety but have different contents. For a package X, the price of one package is p_X yen, and it is known that if you buy one, you can make t_X cups of tea. Find the minimum amount needed to make tea for N people. You may have a package that you don't buy at all, and you don't have to buy a package for just N people (if you can make more than N people). Input format The input is given in the following format. N p_A p_B p_C p_D t_A t_B t_C t_D * The first line gives the number of players participating in the contest. * In the second line, the prices of tea in packages A, B, C and D are given separated by blanks. * The third line gives the number of cups of tea that can be made from packages A, B, C, and D, separated by blanks. Constraint * 1 \ leq N \ leq 100 * 1 \ leq p_X \ leq 100 * 1 \ leq t_X \ leq 100 * All inputs are given as integers. Output format Output the minimum amount required to make tea for N people in one line. Input example 1 Ten 1 2 3 4 1 2 4 8 Output example 1 6 * It's best to buy one package B and one D. Input example 2 Five 2 9 9 8 1 4 5 100 Output example 2 8 * You will have 20 times more tea than you need, but buying one Package D is the cheapest way to get more than 5 cups of tea. Input example 3 twenty four 2 3 4 7 7 9 11 20 Output example 3 8 * It's best to buy two packages A and one C. It may not be possible to make just enough tea for the number of people as in this case. Example Input 10 1 2 3 4 1 2 4 8 Output 6
instruction
0
15,906
10
31,812
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): n = I() p = LI() t = LI() ans = float("inf") for i in range(n+1): x0 = t[0]*i m0 = p[0]*i for j in range(n+1): x1 = x0+t[1]*j m1 = m0+p[1]*j for k in range(n+1): x2 = x1+t[2]*k m2 = m1+p[2]*k rest = max(0,math.ceil((n-x2)/t[3])) m3 = m2+p[3]*rest if m3 < ans: ans = m3 print(ans) return #B def B(): n = I() return #C def C(): n = I() return #D def D(): n = I() return #E def E(): n = I() return #F def F(): n = I() return #G def G(): n = I() return #Solve if __name__ == "__main__": A() ```
output
1
15,906
10
31,813
Provide a correct Python 3 solution for this coding contest problem. A: four tea problem Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed] There are N players participating in the contest, so I would like to prepare tea for this number of people. There are four types of tea packages, A, B, C, and D, all of which are the same variety but have different contents. For a package X, the price of one package is p_X yen, and it is known that if you buy one, you can make t_X cups of tea. Find the minimum amount needed to make tea for N people. You may have a package that you don't buy at all, and you don't have to buy a package for just N people (if you can make more than N people). Input format The input is given in the following format. N p_A p_B p_C p_D t_A t_B t_C t_D * The first line gives the number of players participating in the contest. * In the second line, the prices of tea in packages A, B, C and D are given separated by blanks. * The third line gives the number of cups of tea that can be made from packages A, B, C, and D, separated by blanks. Constraint * 1 \ leq N \ leq 100 * 1 \ leq p_X \ leq 100 * 1 \ leq t_X \ leq 100 * All inputs are given as integers. Output format Output the minimum amount required to make tea for N people in one line. Input example 1 Ten 1 2 3 4 1 2 4 8 Output example 1 6 * It's best to buy one package B and one D. Input example 2 Five 2 9 9 8 1 4 5 100 Output example 2 8 * You will have 20 times more tea than you need, but buying one Package D is the cheapest way to get more than 5 cups of tea. Input example 3 twenty four 2 3 4 7 7 9 11 20 Output example 3 8 * It's best to buy two packages A and one C. It may not be possible to make just enough tea for the number of people as in this case. Example Input 10 1 2 3 4 1 2 4 8 Output 6
instruction
0
15,907
10
31,814
"Correct Solution: ``` #import sys #input = sys.stdin.readline def main(): N = int( input()) p1, p2, p3, p4 = list( map( int, input().split())) t1, t2, t3, t4 = list( map( int, input().split())) ans = 10000 for i in range(N+1): if i*p1 >= ans: break if i*t1 >= N: ans = i*p1 break for j in range(N+1-i): if i*p1 + j*p2 >= ans: break if i*t1 + j*t2 >= N: ans = i*p1 + j*p2 break for k in range(N+1-i-j): if i*t1 + j*t2 + k*t3 >= N: if i*p1 + j*p2 + k*p3 < ans: ans = i*p1 + j*p2 + k*p3 break else: g = (N-i*t1-j*t2-k*t3 + t4-1)//t4 if i*p1 + j*p2 + k*p3 + g*p4 < ans: ans = i*p1 + j*p2 + k*p3 + g*p4 print(ans) if __name__ == '__main__': main() ```
output
1
15,907
10
31,815
Provide a correct Python 3 solution for this coding contest problem. A: four tea problem Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed] There are N players participating in the contest, so I would like to prepare tea for this number of people. There are four types of tea packages, A, B, C, and D, all of which are the same variety but have different contents. For a package X, the price of one package is p_X yen, and it is known that if you buy one, you can make t_X cups of tea. Find the minimum amount needed to make tea for N people. You may have a package that you don't buy at all, and you don't have to buy a package for just N people (if you can make more than N people). Input format The input is given in the following format. N p_A p_B p_C p_D t_A t_B t_C t_D * The first line gives the number of players participating in the contest. * In the second line, the prices of tea in packages A, B, C and D are given separated by blanks. * The third line gives the number of cups of tea that can be made from packages A, B, C, and D, separated by blanks. Constraint * 1 \ leq N \ leq 100 * 1 \ leq p_X \ leq 100 * 1 \ leq t_X \ leq 100 * All inputs are given as integers. Output format Output the minimum amount required to make tea for N people in one line. Input example 1 Ten 1 2 3 4 1 2 4 8 Output example 1 6 * It's best to buy one package B and one D. Input example 2 Five 2 9 9 8 1 4 5 100 Output example 2 8 * You will have 20 times more tea than you need, but buying one Package D is the cheapest way to get more than 5 cups of tea. Input example 3 twenty four 2 3 4 7 7 9 11 20 Output example 3 8 * It's best to buy two packages A and one C. It may not be possible to make just enough tea for the number of people as in this case. Example Input 10 1 2 3 4 1 2 4 8 Output 6
instruction
0
15,908
10
31,816
"Correct Solution: ``` def inpl(): return list(map(int, input().split())) N = int(input()) P = inpl() T = inpl() cost = 10**9 for a in range(-(-N//T[0]) + 1): costa = P[0]*a teaa = T[0]*a rema = N - teaa for b in range(max(1, -(-rema//T[1]) + 1)): costb = P[1] * b teab = T[1]*b remb = max(rema - teab, 0) for c in range(max(1, -(-remb//T[2]) + 1)): costc = P[2] * c teac = T[2] * c remc = max(remb - teac, 0) d = max(-(-remc//T[3]), 0) costd = P[3] * d tead = T[3] * d cost = min(cost, costa + costb + costc + costd) print(cost) ```
output
1
15,908
10
31,817
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,780
10
33,560
"Correct Solution: ``` while True: N = int(input()) if not N: break seeds = [] for i in range(N): plant = input().split() name, price = plant[0], int(plant[1]) seed_to_leaf, leaf_to_fruit = sum(map(int, plant[2:5])), sum(map(int, plant[5:7])) num_per, sold, mult = int(plant[7]), int(plant[8]), int(plant[9]) seeds.append((-(num_per * sold * mult - price) / (seed_to_leaf + leaf_to_fruit * mult), name)) for _, name in sorted(seeds): print(name) print('#') ```
output
1
16,780
10
33,561
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,781
10
33,562
"Correct Solution: ``` while True: n = int(input()) if n == 0: break dic = [] for _ in range(n): lst = input().split() l = lst.pop(0) p, a, b, c, d, e, f, s, m = map(int, lst) time = a + b + c + (d + e) * m prof = f * s * m - p dic.append((-prof / time, l)) dic.sort() for _, name in dic: print(name) print("#") ```
output
1
16,781
10
33,563
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,782
10
33,564
"Correct Solution: ``` while 1: n = int(input()) if n == 0: break ans = [] for i in range(n): l,p,a,b,c,d,e,f,s,m = input().split() p,a,b,c,d,e,f,s,m = map(int,[p,a,b,c,d,e,f,s,m]) sum = s*f*m-p sum /= (a+b+c+d+e+(m-1)*(d+e)) ans.append([l,sum]) ans.sort(key = lambda x: x[0]) ans.sort(key = lambda x: -x[1]) for i in ans: print(i[0]) print("#") ```
output
1
16,782
10
33,565
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,783
10
33,566
"Correct Solution: ``` while True: N = int(input()) if N == 0: break mem = [] for i in range(N): l,p,a,b,c,d,e,f,s,m = map(lambda x:int(x) if x[0].isdigit() else x, input().split()) time = a+b+c+(d+e)*m income = f*m*s - p mem.append((-income/time, l)) for e,name in sorted(mem): print(name) print('#') ```
output
1
16,783
10
33,567
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,784
10
33,568
"Correct Solution: ``` while True: N = int(input()) if N == 0: break effies = {} for _ in range(N): L, P, A, B, C, D, E, F, S, M = map(str, input().split()) P = int(P) A = int(A) B = int(B) C = int(C) D = int(D) E = int(E) F = int(F) S = int(S) M = int(M) spend_time = A + B + C + (D+E) * M earn_amount = (F*M*S)-P effi = earn_amount/spend_time effies[L] = effi effies = sorted(effies.items(), key=lambda x :(-x[1], x[0])) for i in range(len(effies)): print(effies[i][0]) print("#") ```
output
1
16,784
10
33,569
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,785
10
33,570
"Correct Solution: ``` while 1: n=int(input()) if n==0: break D=[] for i in range(n): l,p,a,b,c,d,e,f,s,m=input().split() p,a,b,c,d,e,f,s,m=map(int,(p,a,b,c,d,e,f,s,m)) D.append(((s*f*m-p)/((d+e)*m+a+b+c),l)) D=sorted(D,key=lambda x:(-x[0],x[1])) for i in range(n): print(D[i][1]) print('#') ```
output
1
16,785
10
33,571
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,786
10
33,572
"Correct Solution: ``` resultss = [] while True: N = int(input()) if N == 0: break B = [list(map(str, input().split())) for _ in range(N)] results = [] for i in range(N): A = [] name = B[i][0] B[i][0] = B[i][1] for j in range(10): A.append(int(B[i][j])) if A[-1] == 1: time = A[2] + A[3] + A[4] + A[5] + A[6] money = A[7] * A[8] res = money - A[1] res /= time else: time = A[2] + A[3] + A[4] + A[5] + A[6] + (A[5] + A[6]) * (A[-1] - 1) money = A[7] * A[8] * A[-1] res = money - A[1] res /= time results.append([res, name]) results = sorted(results, key=lambda x: x[1], reverse = True) results = sorted(results, key=lambda x: x[0]) resultss.append(results) for i in range(len(resultss)): for j in range(len(resultss[i])): print(resultss[i][-j-1][1]) print('#') ```
output
1
16,786
10
33,573
Provide a correct Python 3 solution for this coding contest problem. You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour. You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits. Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency. Input The input is a sequence of datasets, and each dataset is given in the following format. > N > L1 P1 A1 B1 C1 D1 E1 F1 S1 M1 > L2 P2 A2 B2 C2 D2 E2 F2 S2 M2 > ... > LN PN AN BN CN DN EN FN SN MN > The first line is the number of crops N in the dataset (1 ≀ N ≀ 50). The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≀ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≀ 100, 1 ≀ Mi ≀ 5. It can be assumed that no crop has the same name in one case. The end of the input is represented by a line containing only one zero. Output For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order. After the output of each data set, output one line consisting of only "#". Example Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
instruction
0
16,787
10
33,574
"Correct Solution: ``` while(True): n = int(input()) if n==0:break agri_list = {} for i in range(n): l,p,a,b,c,d,e,f,s,m = input().split() p = int(p) a = int(a) b = int(b) c = int(c) d = int(d) e = int(e) f = int(f) s = int(s) m = int(m) time = a + b + c + (d + e)* m income = s * m * f - p agri_list[i] = (l,income/time) sorted_items = sorted( agri_list.values(), key = lambda x: (-x[1],x[0])) for i in sorted_items: print(i[0]) print("#") ```
output
1
16,787
10
33,575
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
instruction
0
17,143
10
34,286
Tags: graphs, greedy, sortings Correct Solution: ``` def Fun(n): if(n%2): return n*(n-1)//2+1 return n*n//2 n,m = map(int,input().split()) q = [0] * (m) w = [0] * (m) for i in range(m): q[i],w[i] = [int(x) for x in input().split()] #print(q[i],w[i]) w.sort(reverse = True) #print(*w) s = 0 v = 0 #print("n=",n) for i in range(m): #print("i=",i," v=",v,"w[i]=",w[i]) if(Fun(i+1)>n): break s+=w[i] print(s) # Made By Mostafa_Khaled ```
output
1
17,143
10
34,287
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
instruction
0
17,144
10
34,288
Tags: graphs, greedy, sortings Correct Solution: ``` import itertools def f(n): return n * (n - 1) / 2 + 1 if n % 2 else n * (n - 1) / 2 + n / 2 n, m = map(int, input().split()) table = sorted([int(input().split()[1]) for _ in range(m)], reverse = True) ans = 1 while f(ans) <= n: ans += 1 ans -= 1 print(list(itertools.accumulate(table))[min(ans - 1, m - 1)]) ```
output
1
17,144
10
34,289
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
instruction
0
17,145
10
34,290
Tags: graphs, greedy, sortings Correct Solution: ``` def readdata(): #fread = open('input.txt', 'r') global n, m, w, q n, m = [int(x) for x in input().split()] q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] def podg(): global summ w.sort(reverse = True) summ = [w[0]] * m for i in range(1, m): summ[i] = summ[i - 1] + w[i] def may(k): if (k % 2 == 1): return n > (k * (k - 1)) // 2 return n > (k * (k - 1)) // 2 + (k - 2) // 2 def solve(): for i in range(1, m + 1): if may(i) and not may(i + 1): print(summ[i - 1]) return print(sum(w)) readdata() podg() solve() ```
output
1
17,145
10
34,291
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
instruction
0
17,146
10
34,292
Tags: graphs, greedy, sortings Correct Solution: ``` import sys, bisect (n, m), *s = [map(int, s.split()) for s in sys.stdin.readlines()] g = [n * (n - 1) // 2 + (n - 1) % 2 * (n // 2 - 1) for n in range(1, 2002)] print(sum(sorted([w for _, w in s], reverse=True)[:min(m, bisect.bisect_left(g, n))])) ```
output
1
17,146
10
34,293
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
instruction
0
17,147
10
34,294
Tags: graphs, greedy, sortings Correct Solution: ``` def Fun(n): if(n%2): return n*(n-1)//2+1 return n*n//2 n,m = map(int,input().split()) q = [0] * (m) w = [0] * (m) for i in range(m): q[i],w[i] = [int(x) for x in input().split()] #print(q[i],w[i]) w.sort(reverse = True) #print(*w) s = 0 v = 0 #print("n=",n) for i in range(m): #print("i=",i," v=",v,"w[i]=",w[i]) if(Fun(i+1)>n): break s+=w[i] print(s) ```
output
1
17,147
10
34,295
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
instruction
0
17,148
10
34,296
Tags: graphs, greedy, sortings Correct Solution: ``` n,m = map(int,input().split()) q = [0] * (m) w = [0] * (m) for i in range(m): q[i],w[i] = [int(x) for x in input().split()] #print(q[i],w[i]) w.sort(reverse = True) #print(*w) s = 0 v = 0 #print("n=",n) for i in range(m): i=i+1 if (i % 2 == 1): v = i*(i-1)//2 + 1 else: v=i*i//2 i=i-1 #print("i=",i," v=",v,"w[i]=",w[i]) if(v>n): break s+=w[i] print(s) ```
output
1
17,148
10
34,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2]. Submitted Solution: ``` def readdata(): #fread = open('input.txt', 'r') global n, m, w, q n, m = [int(x) for x in input().split()] q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] def podg(): global summ w.sort(reverse = True) summ = [w[0]] * m for i in range(1, m): summ[i] = summ[i - 1] + w[i] def may(k): if (k % 2 == 1): return n > (k * (k - 1)) // 2 return n > (k * (k - 1)) // 2 + (k - 2 // 2) def solve(): if not may(0): print(2 / 0) for i in range(1, m + 1): if may(i) and not may(i + 1): print(summ[i - 1]) return print(sum(w)) readdata() podg() solve() ```
instruction
0
17,149
10
34,298
No
output
1
17,149
10
34,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2]. Submitted Solution: ``` def readdata(): #fread = open('input.txt', 'r') global n, m, w, q n, m = [int(x) for x in input().split()] q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] def podg(): global summ w.sort(reverse = True) summ = [w[0]] * m for i in range(1, m): summ[i] = summ[i - 1] + w[i] def may(k): if (k % 2 == 1): return n > (k * (k - 1)) // 2 return n > (k * (k - 1)) // 2 + (k - 2 // 2) def solve(): l = 1 r = m + 1 while r - l > 1: mid = (l + r) // 2 if may(mid): l = mid else: r = mid print(summ[l - 1]) readdata() podg() solve() ```
instruction
0
17,150
10
34,300
No
output
1
17,150
10
34,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2]. Submitted Solution: ``` import itertools n, m = map(int, input().split()) table = sorted([int(input().split()[1]) for _ in range(m)], reverse = True) ans = 1 while ans * (ans - 1) / 2 + 1<= n: ans += 1 ans -= 1 print(list(itertools.accumulate(table))[min(ans - 1, m - 1)]) ```
instruction
0
17,151
10
34,302
No
output
1
17,151
10
34,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x β‰  y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≀ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. Input The first line contains two integers n and m (1 ≀ n ≀ 2Β·106, 1 ≀ m ≀ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≀ qi, wi ≀ 105). It is guaranteed that all qi are distinct. Output In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 Note In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2]. Submitted Solution: ``` def readdata(): #fread = open('input.txt', 'r') global n, m, w, q n, m = [int(x) for x in input().split()] q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] def podg(): global summ w.sort(reverse = True) summ = [w[0]] * m for i in range(1, m): summ[i] = summ[i - 1] + w[i] def may(k): if (k % 2 == 1): return n > (k * (k - 1)) // 2 return n > (k * (k - 1)) // 2 + (k - 2 // 2) def solve(): if not may(0): print(2 / 0) for i in range(1, m + 1): if may(i) and not may(i + 1): print(summ[i - 1]) return print(summ[m - 1]) readdata() podg() solve() ```
instruction
0
17,152
10
34,304
No
output
1
17,152
10
34,305
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,332
10
34,664
Tags: greedy, sortings Correct Solution: ``` n, f=map(int, input().split()) a=[] b=[] for i in range (0, n): k, l=map(int, input().split()) a.append(min(2*k, l)-min(k, l)) b.append(min(k, l)) a.sort(reverse=True) ans=0 for i in range (0, f): ans+=a[i] for i in b: ans+=i print(ans) ```
output
1
17,332
10
34,665
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,333
10
34,666
Tags: greedy, sortings Correct Solution: ``` n,f=list(map(int,input().split())) k,l=[0 for i in range(n)],[0 for i in range(n)] for i in range(n): k[i],l[i]=list(map(int,input().split())) p=[min(k[i],l[i]) for i in range(n)] q=[min(2*k[i],l[i]) for i in range(n)] r=[q[i]-p[i] for i in range(n)] r.sort(reverse=True) print(sum(p)+sum(r[:f])) ```
output
1
17,333
10
34,667
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,334
10
34,668
Tags: greedy, sortings Correct Solution: ``` n, f = map(int, input().split()) p = [0]*n s = 0 for i in range(n): k, l = map(int, input().split()) if l >= 2 * k: p[i] = k s += k elif l > k: p[i] = l-k s += k else: s += l s += sum( list(reversed(sorted(p)))[:f]) print(s) ```
output
1
17,334
10
34,669
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,335
10
34,670
Tags: greedy, sortings Correct Solution: ``` # -*- coding: utf-8 -*- import sys import os import math # input_text_path = __file__.replace('.py', '.txt') # fd = os.open(input_text_path, os.O_RDONLY) # os.dup2(fd, sys.stdin.fileno()) n, f = map(int, input().split()) A = [] normal_sell_total = 0 for i in range(n): product_num, client_num = map(int, input().split()) if product_num >= client_num: normal_sell_num = client_num else: normal_sell_num = product_num normal_sell_total += normal_sell_num if product_num * 2 >= client_num: double_sell_num = client_num else: double_sell_num = product_num * 2 diff = double_sell_num - normal_sell_num A.append(diff) A.sort(reverse=True) increased_sell_num = sum(A[:f]) print(normal_sell_total + increased_sell_num) ```
output
1
17,335
10
34,671
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,336
10
34,672
Tags: greedy, sortings Correct Solution: ``` def solve(n, f, kls): base = sum(min(k, l) for k, l in kls) plus = sorted([min(2*k, l) - min(k, l) for k, l in kls])[::-1] res = base + sum(plus[:f]) print(res) def main(): n, f = map(int, input().split()) kls = [] for _ in range(n): k, l = map(int, input().split()) kls.append((k, l)) solve(n, f, kls) if __name__ == '__main__': main() ```
output
1
17,336
10
34,673
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,337
10
34,674
Tags: greedy, sortings Correct Solution: ``` n,f=map(int,input().split()) a=[] for i in range(n): temp=list(map(int,input().split())) if temp[0]>=temp[1]: temp.append(0) elif (temp[0]*2)>=temp[1]: temp.append(temp[1]-temp[0]) else: temp.append(temp[0]) a.append(temp) a.sort(key=lambda x: x[2],reverse=True) sum=0 for i in range(n): if i<f: if (a[i][0]*2)>=a[i][1]: sum+=a[i][1] else: sum+=(a[i][0]*2) elif a[i][0]>=a[i][1]: sum+=a[i][1] else: sum+=a[i][0] print(sum) ```
output
1
17,337
10
34,675
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,338
10
34,676
Tags: greedy, sortings Correct Solution: ``` n,f=map(int,input().split()) w=[[int(x) for x in input().split()]for i in range(n)] sum1=0 final=[0]*n for j in range(len(w)): sum1=sum1+min(w[j][0],w[j][1]) final[j]=min(2*w[j][0],w[j][1])-min(w[j][0],w[j][1]) final.sort(reverse=True) for i in range(f): sum1=sum1+final[i] print(sum1) ```
output
1
17,338
10
34,677
Provide tags and a correct Python 3 solution for this coding contest problem. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out.
instruction
0
17,339
10
34,678
Tags: greedy, sortings Correct Solution: ``` n,k=map(int,input().split()) s=0;e=[] for i in range(n): a,b=map(int,input().split()) c = min(a,b) d = min(2*a,b) s += c e.append(d-c) e.sort() for i in range(n-1,n-k-1,-1): s+=e[i] print(s) ```
output
1
17,339
10
34,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out. Submitted Solution: ``` n,f=map(int,input().split()) ml=[] for i in range(n): k,l=map(int,input().split()) t=((min(2*k,l)-min(k,l)),k,l) ml.append(t) ml.sort(reverse=True) r=0 for i in range(f): r+=min(2*ml[i][1],ml[i][2]) for i in range(f,n): r+=min(ml[i][1],ml[i][2]) print(r) ```
instruction
0
17,340
10
34,680
Yes
output
1
17,340
10
34,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out. Submitted Solution: ``` n,f=input().strip().split(' ') n,f=(int(n),int(f)) list1=[] ans=0 for i in range(n): k,l=input().strip().split(' ') k,l=(int(k),int(l)) ans+=min(k,l) if k<l: list1.append(min(2*k,l)-k) list1.sort() list1.reverse() if f>len(list1): ans1=sum(list1) else: ans1=sum(list1[0:f]) print(ans+ans1) ```
instruction
0
17,341
10
34,682
Yes
output
1
17,341
10
34,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2Β·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. Input The first line contains two integers n and f (1 ≀ n ≀ 105, 0 ≀ f ≀ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers ki, li (0 ≀ ki, li ≀ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. Output Print a single integer denoting the maximal number of products that shop can sell. Examples Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 Note In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second β€” 5, on the third β€” 2, on the fourth β€” 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out. Submitted Solution: ``` '''input 4 1 0 2 0 3 3 5 0 6 ''' n, f = map(int, input().split()) if f == 0: s = 0 for _ in range(n): k, l = map(int, input().split()) s += min(k, l) print(s) else: s = 0 d = [] for _ in range(n): k, l = map(int, input().split()) s += min(k, l) d.append(min(2*k, l) - min(k, l)) print(s + sum(sorted(d)[-f:]) if f > 0 else s) ```
instruction
0
17,342
10
34,684
Yes
output
1
17,342
10
34,685