message
stringlengths
2
30.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
237
109k
cluster
float64
10
10
__index_level_0__
int64
474
217k
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20
instruction
0
82,664
10
165,328
Tags: binary search, greedy Correct Solution: ``` from collections import deque def main(): n, m = map(int, input().split()) wanted_cnt = list(map(int, input().split())) Order = [tuple(map(int, input().split())) for i in range(m)] #count the maximum number which you can buy on sales day. S = sum(wanted_cnt) def ispossible_within(Day): sale_get_cnt = 0 last_sale = [0]*n for day, good in Order: if day > Day: continue last_sale[good-1] = max(last_sale[good-1], day) Que = [] for i in range(n): if wanted_cnt[i] > 0 and last_sale[i] > 0: Que.append((last_sale[i], wanted_cnt[i])) Que.sort() que = deque(Que) while que: sale_day, wanted = que.popleft() money_left = sale_day - sale_get_cnt if money_left >= wanted: sale_get_cnt += wanted elif money_left < wanted: sale_get_cnt += money_left left_money = Day - sale_get_cnt left = S - sale_get_cnt return left_money >= 2*left impossible = 0 possible = 2020 while possible - impossible > 1: m = (impossible + possible)//2 if ispossible_within(m): possible = m else: impossible = m print(possible) return if __name__ == "__main__": main() ```
output
1
82,664
10
165,329
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20
instruction
0
82,665
10
165,330
Tags: binary search, greedy Correct Solution: ``` import collections def main(): from sys import stdin, stdout def read(): return stdin.readline().rstrip('\n') def read_array(sep=None, maxsplit=-1): return read().split(sep, maxsplit) def read_int(): return int(read()) def read_int_array(sep=None, maxsplit=-1): return [int(a) for a in read_array(sep, maxsplit)] def write(*args, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in args) + end) def write_array(array, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in array) + end) def enough(days): bought = [] # (type, amount) bought_total = 0 used_from = days for d in range(days, 0, -1): used_from = min(d, used_from) for t in offers.get(d, []): if K[t] > 0: x = min(K[t], used_from) K[t] -= x bought.append((t, x)) bought_total += x used_from -= x if not used_from: break remaining_money = days - bought_total ans = (total_transaction - bought_total) * 2 <= remaining_money for t, a in bought: K[t] += a return ans n, m = read_int_array() K = read_int_array() total_transaction = sum(K) offers = collections.defaultdict(list) for _ in range(m): d, t = read_int_array() offers[d].append(t-1) low = total_transaction high = low * 2 ans = high while low <= high: mid = (low + high) // 2 if enough(mid): ans = mid high = mid - 1 else: low = mid + 1 write(ans) main() ```
output
1
82,665
10
165,331
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20
instruction
0
82,666
10
165,332
Tags: binary search, greedy Correct Solution: ``` input=__import__('sys').stdin.readline def check(x): last=[0]*(n+1) for i in tmp: if i[0]>x: break else: last[i[1]]=i[0] sal=[0]*(x+1) for i in range(1,n+1): sal[last[i]]+=lis[i-1] c=0 for i in range(1,x+1): c+=1 if sal[i]>=c: sal[i]-=c c=0 else: c-=sal[i] sal[i]=0 if sum(sal)*2<=c: return True else: return False n,m = map(int,input().split()) lis = list(map(int,input().split())) tmp=[] for _ in range(m): a,b = map(int,input().split()) tmp.append([a,b]) tmp.sort() l=0 r=sum(lis)*2 while l<=r: mid = l + (r-l)//2 if check(mid): r = mid-1 else: l = mid+1 if check(r): print(r) elif check(l): print(l) else: print(l+1) ```
output
1
82,666
10
165,333
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20
instruction
0
82,667
10
165,334
Tags: binary search, greedy Correct Solution: ``` import copy from collections import defaultdict BIG = 10**9 N, M = [int(i) for i in input().split()] K = [0] + [int(i) for i in input().split()] sumK = sum(K) max_days = 2*sum(K) day_at_sale_per_item = defaultdict(list) for i in range(M): day, item = [int(i) for i in input().split()] day_at_sale_per_item[item].append(day) sales_per_day = defaultdict(list) for item, days in day_at_sale_per_item.items(): for day in days: sales_per_day[day].append(item) L, R = 0, max_days answer = 0 while L <= R: m = (L+R)//2 def get_best_sales(m): best_sales = defaultdict(list) for item, days in day_at_sale_per_item.items(): best_day = 0 for day in days: if day <= m: best_day = max(best_day, day) if best_day: best_sales[best_day].append(item) return best_sales def available_sales(m): available_money = 0 nb_sales = 0 cK = copy.deepcopy(K) best_sales = get_best_sales(m) for day in range(1, m+1): available_money += 1 for item in best_sales[day]: buy = min(cK[item], available_money) if buy: cK[item] -= buy available_money -= buy nb_sales += buy return nb_sales def possible(m): total_money = m needed_money = 2 * sumK - available_sales(m) return total_money >= needed_money if possible(m): answer = m R = m-1 else: L = m+1 print(answer) ```
output
1
82,667
10
165,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` #!/usr/bin/env python3 import os from io import BytesIO def main(): input = BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m = map(int, input().split()) k = [int(x) for x in input().split()] d = [[] for _ in range(4 * 10**5 + 1)] for j in range(m): dj, tj = map(int, input().split()) d[dj - 1].append(tj - 1) lo, hi = 0, 4 * 10**5 while lo < hi: mi = (hi + lo) // 2 cash = mi offset = 0 _k = k[:] for i in reversed(range(mi)): for j in d[i]: while cash and _k[j]: _k[j] -= 1 cash -= 1 if cash == i + 1: cash -= 2 offset += 1 if 2 * (sum(_k) - offset) <= cash: hi = mi else: lo = mi + 1 os.write(1, str(lo).encode()) if __name__ == "__main__": main() ```
instruction
0
82,668
10
165,336
Yes
output
1
82,668
10
165,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: max(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(10)] pp=[0]*10 def SieveOfEratosthenes(n=10): p = 2 c=0 while (p * p <= n): if (prime[p] == True): c+=1 for i in range(p, n+1, p): pp[i]+=1 prime[i] = False p += 1 #---------------------------------Binary Search------------------------------------------ def binarySearch(arr, n, key): left = 0 right = n-1 mid = 0 res=0 while (left <= right): mid = (right + left)//2 if (arr[mid][0] > key): right = mid-1 else: res=mid left = mid + 1 return res #---------------------------------running code------------------------------------------ n,m=map(int,input().split()) l=list(map(int,input().split())) t=[] for i in range(m): a,b=map(int,input().split()) t.append((a,b)) t.sort() def check(x): now=x c=sum(l) cur=0 last=0 ld=defaultdict(int) for i in range(len(t)): if t[i][0]<=x: ld[t[i][1]]=i for i in range(m): if ld[t[i][1]]!=i: continue if t[i][0]>x: break cur+=t[i][0]-last rt=min(cur,l[t[i][1]-1]) cur-=rt now-=rt c-=rt last=t[i][0] if now>=2*c: return True return False st=1 end=2*sum(l) ans=end while(st<=end): mid=(st+end)//2 if check(mid)==True: ans=mid end=mid-1 else: st=mid+1 print(ans) ```
instruction
0
82,669
10
165,338
Yes
output
1
82,669
10
165,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` import sys import os from io import BytesIO DEBUG = False if DEBUG: inf = open("input.txt") else: # inf = sys.stdin inf = BytesIO(os.read(0, os.fstat(0).st_size)) N, M = list(map(int, inf.readline().split())) n_items = list(map(int, inf.readline().split())) sales = [] for _ in range(M): sale = list(map(int, inf.readline().split())) sales.append(sale) # sale_day, sale_type sales = sorted(sales, key=lambda x: x[0], reverse=True) # sort by day def can_buy_in(dday): used = 0 money_left = dday items = n_items[:] for sale_day, sale_type in sales: if sale_day > dday: continue if money_left > sale_day: money_left = sale_day can_buy = min(items[sale_type-1], money_left) # buy it used += can_buy items[sale_type-1] -= can_buy money_left -= can_buy if money_left == 0: break need_money_for_rest = sum(items) * 2 return need_money_for_rest + used <= dday total_items = sum(n_items) low = total_items high = total_items * 2 # find minimum can_buy day while low <= high: mid = (low + high) // 2 if can_buy_in(mid): high = mid-1 else: low = mid+1 print(low) ```
instruction
0
82,670
10
165,340
Yes
output
1
82,670
10
165,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` #!/usr/bin/env python """<https://github.com/cheran-senthil/PyRival>""" from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip else: _str = str str = lambda x=b"": x if type(x) is bytes else _str(x).encode() def main(): n, m = map(int, input().split()) k = [int(x) for x in input().split()] d = [[] for _ in range(4 * 10**5 + 1)] for j in range(m): dj, tj = map(int, input().split()) d[dj - 1].append(tj - 1) lo, hi = 0, 4 * 10**5 + 1 while lo < hi: mi = (hi + lo) // 2 cash = mi offset = 0 _k = k[:] for i in reversed(range(mi)): for j in d[i]: while cash and _k[j]: _k[j] -= 1 cash -= 1 if cash == i + 1: cash -= 2 offset += 1 if 2 * (sum(_k) - offset) <= cash: hi = mi else: lo = mi + 1 print(lo) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._buffer = BytesIO() self._fd = file.fileno() self._writable = "x" in file.mode or "r" not in file.mode self.write = self._buffer.write if self._writable else None def read(self): if self._buffer.tell(): return self._buffer.read() return os.read(self._fd, os.fstat(self._fd).st_size) def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self._buffer.tell() self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr) self.newlines -= 1 return self._buffer.readline() def flush(self): if self._writable: os.write(self._fd, self._buffer.getvalue()) self._buffer.truncate(0), self._buffer.seek(0) def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", b"\n")) if kwargs.pop("flush", False): file.flush() sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) input = lambda: sys.stdin.readline().rstrip(b"\r\n") # endregion if __name__ == "__main__": main() ```
instruction
0
82,671
10
165,342
Yes
output
1
82,671
10
165,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict # threading.stack_size(10**8) mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase # sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] > k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ class TrieNode: def __init__(self): self.children = [None] * 26 self.isEndOfWord = False class Trie: def __init__(self): self.root = self.getNode() def getNode(self): return TrieNode() def _charToIndex(self, ch): return ord(ch) - ord('a') def insert(self, key): pCrawl = self.root length = len(key) for level in range(length): index = self._charToIndex(key[level]) if not pCrawl.children[index]: pCrawl.children[index] = self.getNode() pCrawl = pCrawl.children[index] pCrawl.isEndOfWord = True def search(self, key): pCrawl = self.root length = len(key) for level in range(length): index = self._charToIndex(key[level]) if not pCrawl.children[index]: return False pCrawl = pCrawl.children[index] return pCrawl != None and pCrawl.isEndOfWord # -----------------------------------------trie--------------------------------- class Node: def __init__(self, data): self.data = data self.count = 0 self.left = None # left node for 0 self.right = None # right node for 1 class BinaryTrie: def __init__(self): self.root = Node(0) def insert(self, pre_xor): self.temp = self.root for i in range(31, -1, -1): val = pre_xor & (1 << i) if val: if not self.temp.right: self.temp.right = Node(0) self.temp = self.temp.right self.temp.count += 1 if not val: if not self.temp.left: self.temp.left = Node(0) self.temp = self.temp.left self.temp.count += 1 self.temp.data = pre_xor def query(self, xor): self.temp = self.root for i in range(31, -1, -1): val = xor & (1 << i) if not val: if self.temp.left and self.temp.left.count > 0: self.temp = self.temp.left elif self.temp.right: self.temp = self.temp.right else: if self.temp.right and self.temp.right.count > 0: self.temp = self.temp.right elif self.temp.left: self.temp = self.temp.left self.temp.count -= 1 return xor ^ self.temp.data # -------------------------bin trie------------------------------------------- n,m=map(int,input().split()) l=list(map(int,input().split())) t=[] for i in range(m): a,b=map(int,input().split()) t.append((a,b)) t.sort() def check(x): now=x c=sum(l) cur=0 last=0 for i in range(len(t)): if t[i][0]<=x: cur+=t[i][0]-last rt=min(cur,l[t[i][1]-1]) cur-=rt now-=rt c-=rt last=t[i][0] if now>=2*c: return True return False st=1 end=2*sum(l) ans=end while(st<=end): mid=(st+end)//2 if check(mid)==True: ans=mid end=mid-1 else: st=mid+1 print(ans) ```
instruction
0
82,672
10
165,344
No
output
1
82,672
10
165,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` import heapq from collections import defaultdict BIG = 10**9 N, M = [int(i) for i in input().split()] K = [0] + [int(i) for i in input().split()] sales_per_item = defaultdict(list) for i in range(M): day, item = [int(i) for i in input().split()] sales_per_item[item].append(day) for item in sales_per_item.keys(): sales_per_item[item] = sorted(sales_per_item[item]) sales_per_day = defaultdict(list) for item, days_in_sale in sales_per_item.items(): for i in range(len(days_in_sale)): negative_days_until_next_sale = -(days_in_sale[i+1] - days_in_sale[i]) if i+1 < len(days_in_sale) else -BIG heapq.heappush(sales_per_day[days_in_sale[i]], (negative_days_until_next_sale, item)) sumK = sum(K) max_days = 2*sum(K) current_money = 0 current_day = 0 while sumK > 0: current_money += 1 current_day += 1 if sales_per_day[current_day]: while current_money > 0 and sales_per_day[current_day]: _, item = heapq.heappop(sales_per_day[current_day]) buy = min(K[item], current_money) if buy: current_money -= buy K[item] -= buy sumK -= buy if current_money >= sumK * 2: break print(current_day) ```
instruction
0
82,673
10
165,346
No
output
1
82,673
10
165,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` n, m = map(int, input().split()) K = list(map(int, input().split())) S = sum(K) S *= 2 P = [] for _ in range(m): P.append(list(map(int, input().split()))) P.sort() endd = {} start = {} for i in range(len(P)): endd[P[i][0]] = i for i in range(len(P) - 1, -1, -1): start[P[i][0]] = i d = 0 today = 0 while S > today: today += 1 d += 1 if today in start: y = start[today] z = endd[today] for i in range(y, z + 1): if P[i][0] == today: if d >= K[P[i][1] - 1]: S -= K[P[i][1] - 1] d -= K[P[i][1] - 1] K[P[i][1] - 1] = 0 elif d > 0: S -= d K[P[i][1] - 1] -= d d = 0 break print(max(1, today)) ```
instruction
0
82,674
10
165,348
No
output
1
82,674
10
165,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions β€” and he won't start playing until he gets all of them. Each day (during the morning) Ivan earns exactly one burle. There are n types of microtransactions in the game. Each microtransaction costs 2 burles usually and 1 burle if it is on sale. Ivan has to order exactly k_i microtransactions of the i-th type (he orders microtransactions during the evening). Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 1 burle and otherwise he can buy it for 2 burles. There are also m special offers in the game shop. The j-th offer (d_j, t_j) means that microtransactions of the t_j-th type are on sale during the d_j-th day. Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing. Input The first line of the input contains two integers n and m (1 ≀ n, m ≀ 1000) β€” the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains n integers k_1, k_2, ..., k_n (0 ≀ k_i ≀ 1000), where k_i is the number of copies of microtransaction of the i-th type Ivan has to order. It is guaranteed that sum of all k_i is not less than 1 and not greater than 1000. The next m lines contain special offers. The j-th of these lines contains the j-th special offer. It is given as a pair of integers (d_j, t_j) (1 ≀ d_j ≀ 1000, 1 ≀ t_j ≀ n) and means that microtransactions of the t_j-th type are on sale during the d_j-th day. Output Print one integer β€” the minimum day when Ivan can order all microtransactions he wants and actually start playing. Examples Input 5 6 1 2 0 2 0 2 4 3 3 1 5 1 2 1 5 2 3 Output 8 Input 5 3 4 2 1 3 2 3 5 4 2 2 5 Output 20 Submitted Solution: ``` import copy from collections import defaultdict BIG = 10**9 N, M = [int(i) for i in input().split()] K = [0] + [int(i) for i in input().split()] sumK = sum(K) max_days = 2*sum(K) sales_per_item = defaultdict(set) for i in range(M): day, item = [int(i) for i in input().split()] sales_per_item[item].add(day) for item in sales_per_item.keys(): sales_per_item[item] = sorted(list(sales_per_item[item]), reverse=True) sales_per_day = defaultdict(list) for item, days_in_sale in sales_per_item.items(): for i in range(len(days_in_sale)): negative_days_until_next_sale = (days_in_sale[i+1] - days_in_sale[i]) if i+1 < len(days_in_sale) else -BIG sales_per_day[days_in_sale[i]].append((negative_days_until_next_sale, item)) for day in sales_per_day.keys(): sales_per_day[day] = sorted(sales_per_day[day]) # print(sales_per_day) L, R = 0, max_days answer = 0 while L <= R: m = (L+R)//2 def available_sales(m): available_money = m+1 answer = 0 cK = copy.deepcopy(K) for day in range(m, 0, -1): # print('d', day, available_money) for _, item in sales_per_day[day]: if available_money == 0: break buy = min(cK[item], available_money) if buy: # print('buy', buy, 'of', item) cK[item] -= buy available_money -= buy answer += buy if available_money == 0: # print('available sales', m, answer) return answer available_money -= 1 # print('available sales', m, answer) return answer def possible(m): total_money = m needed_money = 2 * sumK - available_sales(m) # print(m, 'total', total_money, 'needed', needed_money) return total_money >= needed_money if possible(m): answer = m R = m-1 else: L = m+1 print(answer) ```
instruction
0
82,675
10
165,350
No
output
1
82,675
10
165,351
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,835
10
165,670
Tags: greedy, sortings Correct Solution: ``` from itertools import permutations def main(): n, m, k = map(int, input().split()) l, res = [], [] for _ in range(n): input() l.append(list(tuple(map(int, input().split())) for _ in range(m))) for sb in permutations(l, 2): t = [(b - a, c) for (a, _, c), (_, b, _) in zip(*sb)] v, x = k, 0 for d, c in sorted(t, reverse=True): if d <= 0: break if v >= c: x += d * c v -= c else: x += d * v break res.append(x) print(max(res)) if __name__ == '__main__': main() ```
output
1
82,835
10
165,671
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,836
10
165,672
Tags: greedy, sortings Correct Solution: ``` n,m,k = [int(s) for s in input().split()] BuyingPrice = [] SellingPrice = [] Number_of_items = [] for i in range(n): input() x = [] y = [] z = [] for j in range(m): a,b,c = [int(s) for s in input().split()] x.append(a) y.append(b) z.append(c) BuyingPrice.append(x) SellingPrice.append(y) Number_of_items.append(z) def getProfit(i,j): def takeFirst(z): return z[0] n = [] for w in range(m): n.append((SellingPrice[j][w]-BuyingPrice[i][w],Number_of_items[i][w])) n.sort(key=takeFirst,reverse=True) count = 0 profit = 0 for w in n: if count>=k: break profit += min(w[1],k-count)*max(w[0],0) if(w[0] > 0): count += min(w[1],k-count) return profit profit = 0 for i in range(n): for j in range(n): profit = max(profit,getProfit(i,j)) print(profit) ```
output
1
82,836
10
165,673
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,837
10
165,674
Tags: greedy, sortings Correct Solution: ``` I=lambda:map(int,input().split()) R=range n,m,k=I() def r(a,b,c=k): q=0 for a,b in sorted((b[i][1]-a[i][0],a[i][2])for i in R(m))[::-1]: if a<1or c<1:break q+=a*min(b,c);c-=b return q w=[] for _ in '0'*n:I();w+=[[list(I())for _ in '0'*m]] print(max(r(w[i],w[j])for i in R(n)for j in R(n))) ```
output
1
82,837
10
165,675
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,838
10
165,676
Tags: greedy, sortings Correct Solution: ``` import sys profit = 0 initial = (list(map(int, sys.stdin.readline().split()))) num_planet = initial[0] num_goods = initial[1] capacity = initial[2] stonks = [] for i in range(0, num_planet): #print('Name planetu') name_Planet = str(sys.stdin.readline()) planet = [] for j in range (0, num_goods): elem = (list(map(int,sys.stdin.readline().split()))) planet.append(elem) stonks.append(planet) def Solution(): global profit for i in range(0, len(stonks)): for j in range(0, len(stonks)): tmp = [] for k in range(0, num_goods): if stonks[i][k][0] < stonks[j][k][1]: res = stonks[j][k][1] - stonks[i][k][0] a = (res, stonks[i][k][2]) tmp.append(a) else: pass if len(tmp) > 0: sort_tmp = sorted(tmp, key = lambda x: (-x[0])) y = 0 for y in range(0, capacity): local_profit = 0 i_in_list = 0 if y == capacity: break for x in range(0, len(sort_tmp)): for z in range(0, sort_tmp[i_in_list][1]): if sort_tmp[i_in_list][1] == 0: break local_profit += sort_tmp[i_in_list][0] y+=1 if z == sort_tmp[i_in_list][1]: break if y > capacity -1 or x == len(sort_tmp): break if y > capacity -1 or x == len(sort_tmp): break i_in_list += 1 profit = local_profit if local_profit > profit else profit Solution() print(profit) ```
output
1
82,838
10
165,677
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,839
10
165,678
Tags: greedy, sortings Correct Solution: ``` import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int,minp().split()) n,m,k = mints() planets = [0]*n for i in range(n): name = minp() costs = [0]*m for j in range(m): costs[j] = tuple(mints()) planets[i] = costs def profit(a,b): offers = [0]*m for i in range(m): offers[i] = (b[i][1]-a[i][0],a[i][2]) #print(offers) offers.sort(reverse=True) z = 0 r = 0 for i in range(m): if offers[i][0] > 0: w = min(k-z,offers[i][1]) z += w #print(w, offers[i][0]) r += w*offers[i][0] return r mp = 0 for i in range(n): for j in range(n): if i != j: mp = max(mp, profit(planets[i],planets[j])) print(mp) ```
output
1
82,839
10
165,679
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,840
10
165,680
Tags: greedy, sortings Correct Solution: ``` I=lambda:map(int,input().split()) R=range n,m,k=I() def r(a,b,c=k): q=0 for a,b in sorted((b[i][1]-a[i][0],a[i][2])for i in R(m))[::-1]: if a<1or c<1:break q+=a*min(b,c);c-=b return q w=[] for _ in '0'*n:I();w+=[[list(I())for _ in '0'*m]] print(max(r(w[i],w[j])for i in R(n)for j in R(n))) # Made By Mostafa_Khaled ```
output
1
82,840
10
165,681
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,841
10
165,682
Tags: greedy, sortings Correct Solution: ``` import math n,m,k=map(int,input().split()) q,z,y,pp={},-math.inf,[],k for i in range(n): input();q[i]=[] for j in range(m): q[i].append(list(map(int,input().split()))) for i in q: r=[] for j in q: o=[] if i!=j: for p in range(m): o.append([(q[j][p][1]-q[i][p][0]),q[i][p][2]]) r.append(o) y.append(r) for i in y: for j in i: j.sort(reverse=True) h,k=0,pp for p in j: if p[0]>0 and k>0:h+=p[0]*min(p[1],k);k-=p[1] z=max(z,h) print(z) ```
output
1
82,841
10
165,683
Provide tags and a correct Python 3 solution for this coding contest problem. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
instruction
0
82,842
10
165,684
Tags: greedy, sortings Correct Solution: ``` n, m, k = map(int, input().split()) planets = [] for i in range(n): name = input() planets.append([]) for j in range(m): item = list(map(int, input().split())) planets[-1].append(item) res = float("-inf") from itertools import permutations for p1, p2 in permutations(planets, 2): sis = sorted(range(m), key=lambda i :p2[i][1] - p1[i][0], reverse=True) cl = k t = 0 for i in sis: if cl == 0 or p2[i][1] - p1[i][0] <= 0: break taken = min(cl, p1[i][2]) t += (p2[i][1] - p1[i][0]) * taken cl -= taken res = max(res, t) print(res) ```
output
1
82,842
10
165,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def MAP2():return map(float,input().split()) def LIST(): return list(map(int, input().split())) def STRING(): return input() import string import sys from heapq import heappop , heappush from bisect import * from collections import deque , Counter , defaultdict from math import * from itertools import permutations , accumulate dx = [-1 , 1 , 0 , 0 ] dy = [0 , 0 , 1 , - 1] #visited = [[False for i in range(m)] for j in range(n)] # primes = [2,11,101,1009,10007,100003,1000003,10000019,102345689] #sys.stdin = open(r'input.txt' , 'r') #sys.stdout = open(r'output.txt' , 'w') #for tt in range(INT()): #arr.sort(key=lambda x: (-d[x], x)) Sort with Freq #Code def solve(i , j ): l = [] for x in range(m): l.append([(sell_price[j][x]-buy_price[i][x]) ,number_items[i][x]]) l.sort(key=lambda x : x[0] , reverse=True) profit = 0 count = 0 for item in l : if count >= k: break profit += min(item[1] , k - count) * max(0 , item[0]) if item[0] > 0 : count+=min(item[1],k-count) return profit n , m , k = MAP() buy_price = [] sell_price = [] number_items = [] for i in range(n): s = input() v1 = [] v2 = [] v3 = [] for j in range(m): l = LIST() v1.append(l[0]) v2.append(l[1]) v3.append(l[2]) buy_price.append(v1) sell_price.append(v2) number_items.append(v3) ans = 0 for i in range(n): for j in range(n): if i != j : ans = max(ans,solve(i,j)) print(ans) ```
instruction
0
82,843
10
165,686
Yes
output
1
82,843
10
165,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` import sys profit=0 initial=(list(map(int,sys.stdin.readline().split()))) num_planet=initial[0] num_goods=initial[1] capacity=initial[2] stonks=[] for i in range (0, num_planet): name_planet=str(sys.stdin.readline()) planet=[] for j in range (0, num_goods): elem=(list(map(int,sys.stdin.readline().split()))) planet.append(elem) stonks.append(planet) def Solution(): global profit pair=[] for i in range (0, len(stonks)): for j in range (0, len(stonks)): tmp=[] for k in range (0, num_goods): if stonks[i][k][0]<stonks[j][k][1]: res=stonks[j][k][1]-stonks[i][k][0] a=(res, stonks[i][k][2]) tmp.append(a) else: pass if len(tmp)>0: sort_tmp=sorted(tmp, key = lambda x: (-x[0])) y=0 for y in range (0, capacity): local_profit=0 i_in_list=0 if y == capacity: break for x in range (0, len(sort_tmp)): for z in range (0, sort_tmp[i_in_list][1]): if sort_tmp[i_in_list][1]==0: break local_profit+=sort_tmp[i_in_list][0] y+=1 if z==sort_tmp[i_in_list][1]: break if y > capacity-1 or x==len(sort_tmp): break if y > capacity-1 or x==len(sort_tmp): break i_in_list+=1 profit = local_profit if local_profit > profit else profit Solution() print(profit) ```
instruction
0
82,844
10
165,688
Yes
output
1
82,844
10
165,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` import math n,m,k=map(int,input().split()) q,z,y,pp={},-math.inf,[],k for i in range(n): input();q[i]=[] for j in range(m): q[i].append(list(map(int,input().split()))) for i in q: r=[] for j in q: o=[] for p in range(m): o.append([(q[j][p][1]-q[i][p][0]),q[i][p][2]]) r.append(o) y.append(r) for i in y: for j in i: j.sort(reverse=True) h,k=0,pp for p in j: if p[0]>0 and k>0:h+=p[0]*min(p[1],k);k-=p[1] z=max(z,h) print(z) ```
instruction
0
82,845
10
165,690
Yes
output
1
82,845
10
165,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` class Planeta: def __init__(self): self.nome = input() self.precoDeComprar = {} self.precoDeVender = {} self.estoqueNoPlaneta = {} for i in range(0, m): s = list(map(int, input().split())) self.precoDeComprar[i] = s[0] self.precoDeVender[i] = s[1] self.estoqueNoPlaneta[i] = s[2] def __hash__(self): return hash(self.nome) n, m, k = list(map(int, input().split())) planetas = [] for i in range(0, n): planetas.append(Planeta()) maximumProfit = 0 for i in range(0, n): for j in range(0, n): if (i != j): p1 = planetas[i] p2 = planetas[j] lucroTabela = {} l = 0 holding = 0 for x in range(0, m): lucroTabela[x] = p2.precoDeVender[x] - p1.precoDeComprar[x] lucroOrdenado = list(lucroTabela.keys()) lucroOrdenado.sort(key = lambda x: lucroTabela[x], reverse=True) for x in lucroOrdenado: if (lucroTabela[x] > 0): quantoComprar = min(p1.estoqueNoPlaneta[x], k - holding) l += lucroTabela[x] * quantoComprar holding += quantoComprar if (l > maximumProfit): maximumProfit = l print(maximumProfit) ```
instruction
0
82,846
10
165,692
Yes
output
1
82,846
10
165,693
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` class Planeta: def __init__(self): self.nome = input() self.precoDeComprar = {} self.precoDeVender = {} self.estoqueNoPlaneta = {} for i in range(0, m): s = list(map(int, input().split())) self.precoDeComprar[i] = s[0] self.precoDeVender[i] = s[1] self.estoqueNoPlaneta[i] = s[2] def __hash__(self): return hash(self.nome) n, m, k = list(map(int, input().split())) planetas = [] for i in range(0, n): planetas.append(Planeta()) maximumProfit = 0 for i in range(0, n): for j in range(0, n): if (i != j): p1 = planetas[i] p2 = planetas[j] lucro = {} l = 0 holding = 0 for x in range(0, m): lucro[x] = p2.precoDeVender[x] - p1.precoDeComprar[x] if (lucro[x] > 0): mini = min(p1.estoqueNoPlaneta[x], k - holding) l += lucro[x] * mini holding += mini if (l > maximumProfit): maximumProfit = l print(maximumProfit) ```
instruction
0
82,847
10
165,694
No
output
1
82,847
10
165,695
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` class Planeta: def __init__(self): self.nome = input() self.precoDeComprar = {} self.precoDeVender = {} self.estoqueNoPlaneta = {} for i in range(0, m): s = list(map(int, input().split())) self.precoDeComprar[i] = s[0] self.precoDeVender[i] = s[1] self.estoqueNoPlaneta[i] = s[2] def __hash__(self): return hash(self.nome) n, m, k = list(map(int, input().split())) planetas = [] for i in range(0, n): planetas.append(Planeta()) maximumProfit = 0 for i in range(0, n): for j in range(0, n): p1 = planetas[i] p2 = planetas[j] lucro = {} l = 0 holding = 0 for x in range(0, m): lucro[x] = p2.precoDeVender[x] - p1.precoDeComprar[x] if (lucro[x] > 0): mini = min(p1.estoqueNoPlaneta[x], k - holding) l += lucro[x] * mini holding += mini if (l > maximumProfit): maximumProfit = l print(maximumProfit) ```
instruction
0
82,848
10
165,696
No
output
1
82,848
10
165,697
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` import math n,m,k=map(int,input().split()) q,z,y={},-math.inf,[] for i in range(n): input();q[i]=[] for j in range(m): q[i].append(list(map(int,input().split()))) for i in q: r=[] for j in q: o=[] for p in range(m): o.append([(q[j][p][1]-q[i][p][0]),q[i][p][2]]) o.sort(reverse=True) r.append(o) y.append(r) for i in y: for j in i: h=0 for p in j: if p[0]>0:h+=p[0]*min(p[1],k);k-=p[1] z=max(z,h) print(z) ```
instruction
0
82,849
10
165,698
No
output
1
82,849
10
165,699
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case. Submitted Solution: ``` n,m,k = [int(s) for s in input().split()] BuyingPrice = [] SellingPrice = [] Number_of_items = [] for i in range(n): input() x = [] y = [] z = [] for j in range(m): a,b,c = [int(s) for s in input().split()] x.append(a) y.append(b) z.append(c) BuyingPrice.append(x) SellingPrice.append(y) Number_of_items.append(z) def getProfit(i,j): def takeFirst(z): return z[0] n = [] for w in range(m): n.append((SellingPrice[j][w]-BuyingPrice[i][w],Number_of_items[i][w])) n.sort(key=takeFirst,reverse=True) count = 0 profit = 0 for w in n: if count>=k: break profit += min(w[1],k-count)*max(w[0],0) if(w[0] > 0): count += min(w[1],k-count) return profit profit = 0 for i in range(n): for j in range(m): profit = max(profit,getProfit(i,j)) print(profit) ```
instruction
0
82,850
10
165,700
No
output
1
82,850
10
165,701
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` n,m = [int(x) for x in input().strip().split()] arr = [] count = 0 for i in range(0,n): a = [int(x) for x in input().strip().split()] if a[0]==0: count+=1 arr.append(a[1:]) d = {i:[] for i in range(0,n)} for i in range(0,n-1): for j in range(i+1,n): if set(arr[i]).intersection(set(arr[j])): d[i].append(j);d[j].append(i) cost = -1 def dfs(v,G,visited): if visited[v]: return 0 s = [v] while s: a = s.pop() for i in G[a]: if not visited[i]: s.append(i) visited[a] = True return 1 visited = [False]*n for i in range(0,n): cost+= dfs(i,d,visited) if count==n: print(count) else: print(cost) ```
instruction
0
82,866
10
165,732
Yes
output
1
82,866
10
165,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` def recursive_dfs(graph, start, path=[]): '''recursive depth first search from start''' path=path+[start] for node in graph[start]: if not node in path: path=recursive_dfs(graph, node, path) return path def connected(x, y): if set(x).intersection(set(y)) != set(): return True return False vertices = [] each = {} adj = {} num0 = 0 a, b = map(int, input().split(' ')) for i in range(a): x = list(map(int, input().split(' '))) adj[i] = [] if x[0] == 0: num0 += 1 else: x = x[1:] each[i] = x vertices.append(i) for j in vertices: if connected(each[j], each[i]): adj[j].append(i) adj[i].append(j) marked = [False] * a num = 0 for i in vertices: if not marked[i]: for j in recursive_dfs(adj, i): marked[j] = True num += 1 if num == 0: print(num0) else: print(num+num0-1) ```
instruction
0
82,867
10
165,734
Yes
output
1
82,867
10
165,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` from collections import defaultdict n, m = [int(i) for i in input().strip().split()] emp_knows = defaultdict(lambda: set()) visited = set() knows_none = True for i in range(1, n+1): data = [int(i) for i in input().strip().split()] for d in data[1:]: knows_none = False emp_knows[i].add(d) def dfs(start): visited.add(start) for i in range(1, n+1): if i not in visited: for lang in range(1, m+1): if lang in emp_knows[i] and lang in emp_knows[start]: dfs(i) ans = 0 for i in range(1, n+1): if i not in visited: dfs(i) ans += 1 if knows_none: print(n) else: print(ans-1) ```
instruction
0
82,868
10
165,736
Yes
output
1
82,868
10
165,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` class DisjointSet: #only support query, NO construction supported def __init__(self, n): self.num_sets = n #--@union self.parents = list(range(n)) self.ranks = [0] * n self.sizes = [1] * n #used@union: size of set@root! 0 if NOT repsentive def find(self,j): while self.parents[j]!=j: jj = self.parents[j] self.parents[j] = self.parents[jj] #partial compression j = jj return j def union(self,i,j): r0 = self.find(i) r1 = self.find(j) if r0 == r1: return False rd = self.ranks[r0] - self.ranks[r1] if rd == 0: # Increment repr0's rank if both nodes have same rank self.ranks[r0] += 1 elif rd < 0: # Swap to ensure that repr0's rank >= repr1's rank r0, r1 = r1, r0 self.parents[r1] = r0 #merge self.sizes[r0] += self.sizes[r1] self.sizes[r1] = 0 self.num_sets -= 1 return True n,m = list(map(int,input().split())) lll = [list(map(int,input().split())) for _ in range(n)] dsu = DisjointSet(n) #tricky, choose n or m? rep = [None]*(m+1) #one representive for each language cnt = 0 hl = False #in case every one speak NONE(case 4) for i,ll in enumerate(lll): for l in ll[1:]: hl = True if rep[l] is None: rep[l] = i else: dsu.union(i,rep[l]) print(dsu.num_sets-1 if hl else dsu.num_sets) ```
instruction
0
82,869
10
165,738
Yes
output
1
82,869
10
165,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` from collections import defaultdict n,m=map(int,input().split()) a=[] graph=defaultdict(list) for i in range(n): a.append(list(map(int,input().split()))) for i in range(n): for j in range(n): if i!=j: for k in range(1,a[i][0]+1): for l in range(1,a[j][0]+1): if a[i][k]==a[j][l]: graph[i].append(j) def dfs(n): vis[n]=1 for i in graph[n]: if not vis[i]: dfs(i) vis=[0]*n ans=-1 for i in range(n): if not vis[i]: ans+=1 dfs(i) print(ans) ```
instruction
0
82,870
10
165,740
No
output
1
82,870
10
165,741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` from collections import defaultdict, deque from sys import* def bfs(g, v, i): q=deque([i]) usd=set() while q: t=q.popleft() usd.add(t) for j in g[t]: if v[j]: break v[j]=True if j not in usd: q.appendleft(j) if len(usd)==1: return [] return usd def solve(n, m, s): ans = 0 q = deque([]) v = [False]*(m+1) for i in s: d = bfs(s, v, i) if d: q+=[d] return max(len(q)-1,0) def main(): n, m = map(int, stdin.readline().split()) s = defaultdict(list) q = 0 for _ in range(n): k, *a = [int(i)for i in stdin.readline().split()] for i in range(k): s[a[i]]+=a[:i]+a[i+1:] if k==0: q+=1 print(solve(n, m, s) + q) main() ```
instruction
0
82,871
10
165,742
No
output
1
82,871
10
165,743
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` n,m=map(int,input().strip().split()) arr=[] v=0 for k in range(m): list1=list(map(int,input().strip().split())) list1=list1[1:] if list1==[]: v+=1 else: arr.append(set(list1)) i=0 while i<len(arr): flag=True for j in arr[i+1:]: if arr[i]&j: arr[i]|=j arr.remove(j) flag=False break if flag: i+=1 if len(arr)==0: print(v) else: print(v+len(arr)-1) ```
instruction
0
82,872
10
165,744
No
output
1
82,872
10
165,745
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` class Node: def __init__(self, n): self.root = n self.parent = None self.children = [] def find(self): return self.root def union(self, other): print(f"Union {self.root} {other.root}") if other.root == self.root: return to_add = other while to_add.parent is not None: to_add = other.parent self.children.append(to_add) to_add.parent = self def change_root(node, root): node.root = root for child in node.children: change_root(child, root) change_root(to_add, self.root) if __name__ == '__main__': num_p, num_l = [int(a) for a in input().split()] known_languages = set() roots = [Node(i) for i in range(101)] no_lang = 0 for _ in range(num_p): languages = [int(a) for a in input().split()][1:] if not languages: no_lang += 1 continue first = None for l in languages: known_languages.add(l) if first is None: first = l continue roots[first].union(roots[l]) print(len(set(roots[k].root for k in known_languages)) - 1 + no_lang) ```
instruction
0
82,873
10
165,746
No
output
1
82,873
10
165,747
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,894
10
165,788
Tags: greedy, implementation Correct Solution: ``` n = int(input()) L = list(map(int,input().split())) a=p=0 for i in L: if i==25: a+=1 elif i==50: a-=1 p+=1 else: if p>0: p-=1 a-=1 else: a-=3 if a<0: print('NO') break else: print('YES') ```
output
1
82,894
10
165,789
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,895
10
165,790
Tags: greedy, implementation Correct Solution: ``` a,b=input(),list(map(int,input().split())) fifties=0 twenties=0 yes='YES' for i in b: if i==25: twenties+=1 elif i==50: if twenties>0: twenties-=1 fifties+=1 else: yes='NO' else: if twenties>0 and fifties>0: twenties-=1 fifties-=1 elif twenties>2: twenties-=3 else: yes='NO' print(yes) ```
output
1
82,895
10
165,791
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,896
10
165,792
Tags: greedy, implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) a=0 b=0 c=0 check=True for i in l: if(i==25): a+=1 elif(i==50 and a>=1): b+=1 a-=1 elif(i==100 and (a>=3 or (a>=1 and b>=1))): c+=1 if(b>=1): b-=1 a-=1 else: a-=3 else: print("NO") check=False break if(check): print("YES") ```
output
1
82,896
10
165,793
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,897
10
165,794
Tags: greedy, implementation Correct Solution: ``` n = int(input()) nums = [int(x) for x in input().split(" ")] count_25 = 0 count_50 = 0 count_100 = 0 for num in nums: if num == 25: count_25 += 1 if num == 50: count_50 += 1 count_25 -= 1 if num == 100: if count_50 != 0: count_50 -= 1 count_25 -= 1 else: count_25 -= 3 if count_50 < 0 or count_25 < 0: print("NO") exit(0) print("YES") ```
output
1
82,897
10
165,795
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,898
10
165,796
Tags: greedy, implementation Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): n = I() a = LI() b = [0,0] for c in a: if c == 25: b[0] += 1 elif c == 50: if b[0] < 1: return 'NO' b[0] -= 1 b[1] += 1 else: if b[0] > 0 and b[1] > 0: b[0] -= 1 b[1] -= 1 continue if b[0] < 3: return 'NO' b[0] -= 3 return 'YES' print(main()) ```
output
1
82,898
10
165,797
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,899
10
165,798
Tags: greedy, implementation Correct Solution: ``` def possible_change(l): twenty_fives = 0 fivties = 0 for currency in l: # 25 if currency == 25: twenty_fives += 1 # 50 elif currency == 50: if twenty_fives >= 1: twenty_fives -= 1 fivties += 1 else: return "NO" # 100 elif currency == 100: if twenty_fives >= 1 and fivties >= 1: fivties -= 1 twenty_fives -= 1 elif twenty_fives >= 3: twenty_fives -= 3 else: return "NO" return "YES" def main(): first_line = input() first_line = first_line.split() n = int(first_line[0]) l = input().split() for i in range(len(l)): l[i] = int(l[i]) print(possible_change(l)) main() ```
output
1
82,899
10
165,799
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,900
10
165,800
Tags: greedy, implementation Correct Solution: ``` if __name__ == '__main__': n = int(input()) massiv = list(map(int, input().split())) c_25, c_50, c_100 = 0, 0, 0 mes = "" for i in massiv: if i == 25: c_25 += 1 elif i == 50: if c_25 != 0: c_25 -= 1 c_50 += 1 else: mes = "NO" break else: if c_25 != 0 and c_50 != 0: c_50 -= 1 c_25 -= 1 elif c_25 >= 3: c_25 -= 3 c_100 += 1 else: mes = "NO" break mes = "YES" print(mes) ```
output
1
82,900
10
165,801
Provide tags and a correct Python 3 solution for this coding contest problem. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO
instruction
0
82,901
10
165,802
Tags: greedy, implementation Correct Solution: ``` n = int(input()) l = list(map(int,input().split())) d={25:0,50:0,100:0} for i in l: if i==25: d[i]+=1 elif i==50: d[50]+=1 if d[25]>0: d[25]-=1 else: print("NO") exit() else: d[100]+=1 if d[25]>0 and d[50]>0: d[25]-=1 d[50]-=1 elif d[25]>2: d[25]-=3 else: print("NO") exit() print("YES") ```
output
1
82,901
10
165,803
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO Submitted Solution: ``` n = int(input()) m = [int(_) for _ in input().split()] x = 0 i = 0 p = 0 while i<n and x>=0: if m[i]==25: x+=1 elif m[i] == 50 and x>0 : x -= 1 p += 1 elif m[i] == 100 and p>0: x -= 1 p -= 1 elif m[i] == 100 and x>=3: x -= 3 elif m[i] == 50: x -= 1 else: x = -1 i+=1 if x>=0: print("YES") else: print("NO") ```
instruction
0
82,902
10
165,804
Yes
output
1
82,902
10
165,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO Submitted Solution: ``` n = int(input()) a = input() A = [] for i in a.split(): A.append(int(i)) count = 0 a = 0 b = 0 c = 0 for j in range(0,n): if A[j] == 25: a = a + 1 elif A[j] == 50: a = a -1 b = b +1 if a <0: c =1 break elif A[j] == 100: if b >0 and a>0: b = b-1 a = a-1 if a<0: c =1 break elif b ==0 and a>0: a = a-3 if a<0: c = 1 break else: c = 1 break if c==1: print('NO') elif c == 0: print('YES') ```
instruction
0
82,903
10
165,806
Yes
output
1
82,903
10
165,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO Submitted Solution: ``` from sys import stdin n = int(stdin.readline().rstrip()) nums = map(int, stdin.readline().rstrip().split(' ')) twenties = 0 fifties = 0 cost = 25 broke = False for num in nums: if num == 25: twenties += 1 elif num == 50: if twenties == 0: print('NO') broke = True break else: twenties -= 1; fifties += 1 else: if fifties >= 1 and twenties >= 1: fifties -= 1; twenties -= 1 elif twenties >= 3: twenties -= 3 else: print('NO') broke = True break if not broke: print('YES') ```
instruction
0
82,904
10
165,808
Yes
output
1
82,904
10
165,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO Submitted Solution: ``` n = int(input()) e = input() a = [int(x) for x in e.split()] f, ff = 0, 0 flag = 1 for i in a: if i == 25: f += 1 if i == 50: f -= 1 ff += 1 if f < 0: flag = 0 break if i == 100: if ff >= 1: if f >= 1: ff -= 1 f -= 1 else: flag = 0 break else: if f < 3: flag = 0 break else: f -= 3 if flag == 0: print('NO') else: print('YES') ```
instruction
0
82,905
10
165,810
Yes
output
1
82,905
10
165,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO Submitted Solution: ``` n = int(input()) a = [int(i) for i in input().split()] t = 0 r = 0 for i in range(n): if a[i] == 25: t += 1 if a[i] == 50: t -= 1 if a[i] == 100: t -= 2 if t < 0: r = 1 if r == 1: print('NO') else: print('YES') ```
instruction
0
82,906
10
165,812
No
output
1
82,906
10
165,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Examples Input 4 25 25 50 50 Output YES Input 2 25 100 Output NO Input 4 50 50 25 25 Output NO Submitted Solution: ``` n = int(input()) arr = [int(num) for num in input().split(' ')] from collections import defaultdict di = defaultdict(int) ans = 'YES' for item in arr: d = item - 25 if di[d]==0 and d!=0: ans = 'NO' break else: di[d] = di[d] - 1 di[item] = di[item] + 1 print(ans) ```
instruction
0
82,907
10
165,814
No
output
1
82,907
10
165,815