description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
T = int(input()) while T > 0: N, M = list(map(int, input().split())) Ci = list(map(int, input().split())) prof = 0 order = [0] * N for i in range(N): D, F, B = map(int, input().split()) if Ci[D - 1] > 0: prof += F Ci[D - 1] -= 1 order[i] = D else: prof += B order[i] = 0 stock = [] for i in range(M): if Ci[i] != 0: stock.append([i, Ci[i]]) k = 0 for i in range(N): if order[i] == 0: order[i] = stock[k][0] + 1 stock[k][1] -= 1 if stock[k][1] == 0: k += 1 print(prof) print(*order) T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) def printlist(ll): st = "" for i in ll: st += str(i) + " " return st for x in range(0, t): profit = 0 n, m = map(int, input().split()) fos = [0] * n tbd = [] flavours = list(map(int, input().split())) for y in range(0, n): d, f, b = map(int, input().split()) if flavours[d - 1] > 0: flavours[d - 1] = flavours[d - 1] - 1 profit += f fos[y] = d else: tbd.append(y) profit += b c = 0 for y in range(0, len(flavours)): while flavours[y] > 0 and c < len(tbd): fos[tbd[c]] = y + 1 flavours[y] -= 1 c += 1 if c >= len(tbd): break print(profit) print(printlist(fos))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for t in range(int(input())): n, m = map(int, input().split()) l = list(map(int, input().split())) x = [] ans = [] cost = 0 rem = [] for i in range(n): c = list(map(int, input().split())) x.append(c) for i in range(len(x)): if l[x[i][0] - 1] > 0: l[x[i][0] - 1] -= 1 ans.append(x[i][0]) cost += x[i][1] else: rem.append(i) cost += x[i][2] q = 0 k = 0 while k < len(rem): if l[q] > 0: ans.insert(rem[k], q + 1) l[q] -= 1 k += 1 else: q += 1 print(cost) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(t): n, m = [int(x) for x in input().split()] arr = [] amt = [int(x) for x in input().split()] cost = 0 brr = [(0) for i in range(n)] for j in range(n): arr.append([int(y) for y in input().split()]) if amt[arr[j][0] - 1] > 0: amt[arr[j][0] - 1] -= 1 cost += arr[j][1] brr[j] = arr[j][0] r = 0 for j in range(n): if brr[j] == 0: for k in range(r, m): if amt[k] > 0: r = k amt[k] -= 1 cost += arr[j][2] brr[j] = k + 1 break print(cost) for j in range(n - 1): print(brr[j], end=" ") print(brr[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
from sys import stdin, stdout input = stdin.readline for T in range(int(input())): N, M = map(int, input().split()) C = list(map(int, input().split())) profit = 0 order = [-1] * N for i in range(N): D, F, B = map(int, input().split()) if C[D - 1] > 0: profit += F C[D - 1] -= 1 order[i] = D else: profit += B remaining = {} for i in range(M): if C[i] > 0: remaining[i + 1] = C[i] id = 0 keys = list(remaining.keys()) count = 0 for i in range(N): if order[i] == -1: key = keys[id] order[i] = key count += 1 if remaining[key] == count: id += 1 count = 0 print(profit) print(*order)
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(t): n, m = map(int, input().split()) c = list(map(int, input().split())) a = [(0) for _ in range(n)] p = 0 for j in range(n): d, f, b = map(int, input().split()) if c[d - 1] > 0: c[d - 1] = c[d - 1] - 1 p = p + f a[j] = d else: p = p + b k = 0 j = 0 while j < n: if a[j] == 0 and c[k] != 0: a[j] = k + 1 c[k] = c[k] - 1 elif a[j] == 0 and c[k] == 0: k = k + 1 j = j - 1 j = j + 1 print(p) print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
testcase = int(input()) for i in range(testcase): n, m = input().split() n, m = [int(n), int(m)] c = [int(i) for i in input().split()] dg = [] l2 = [] output = [0] * n count = 0 for j in range(n): d, f, b = input().split() d, f, b = [int(d), int(f), int(b)] l2.append([d, f, b]) if c[d - 1] > 0: output[j] = d count += f c[d - 1] -= 1 else: count += b for i in range(m): if c[i] > 0: dg.append(i + 1) for i in range(n): if output[i] == 0: output[i] = dg[0] c[dg[0] - 1] -= 1 if c[dg[0] - 1] == 0: dg = dg[1:] print(count) print(" ".join([str(i) for i in output]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for z in range(t): n, m = map(int, input().split()) c = list(map(int, input().split())) rd = {} profit = 0 lessprofit = 0 ans = [] remaining = [] for i in range(n): di, fi, bi = map(int, input().split()) if c[di - 1] > 0: c[di - 1] -= 1 profit += fi ans.append(di) else: lessprofit += bi ans.append(-1) print(profit + lessprofit) j = 0 for i in range(n): if ans[i] == -1: while c[j] == 0: j += 1 ans[i] = j + 1 c[j] -= 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
T = int(input()) for _ in range(T): n, m = list(map(int, input().split())) c = list(map(int, input().split())) q = [] p = 0 y = 0 x = [] for i in range(n): d, f, b = list(map(int, input().split())) if c[d - 1] > 0: c[d - 1] -= 1 p += f q += [d] else: q += [-1] y += 1 p += b for i in range(m): if c[i] != 0: x += [[i, c[i]]] for i in range(n): if q[i] == -1: if x[-1][1] > 0: x[-1][1] -= 1 q[i] = x[-1][0] + 1 else: x.pop() x[-1][1] -= 1 q[i] = x[-1][0] + 1 print(p) print(*q)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR LIST VAR VAR LIST NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR LIST LIST VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) l = [0] * (m + 1) assign = [0] * (n + 1) s = 0 k = list(map(int, input().split())) for i in range(m): l[i + 1] = k[i] for i in range(n): d, f, b = map(int, input().split()) if l[d] > 0: l[d] -= 1 s += f assign[i] = d else: s += b j = 0 while l[j] == 0: j += 1 for i in range(n): if assign[i] == 0: if l[j] != 0: l[j] -= 1 assign[i] = j else: while l[j] == 0: j += 1 l[j] -= 1 assign[i] = j print(s) for i in range(n): print(assign[i], end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(t): d = [] f = [] b = [] profit = 0 n, m = [int(x) for x in input().split()] order = [(0) for j in range(n)] flav = [int(x) for x in input().split()] for j in range(n): inp = [int(x) for x in input().split()] d.append(inp[0]) f.append(inp[1]) b.append(inp[2]) for j in range(n): if flav[d[j] - 1] > 0: profit = profit + f[j] flav[d[j] - 1] -= 1 order[j] = d[j] flag = 0 for j in range(n): if order[j] == 0: for k in range(flag, n): if flav[flag] > 0: order[j] = flag + 1 flav[flag] -= 1 profit += b[j] break else: flag += 1 print(profit) for k in range(len(order) - 1): print(order[k], end=" ") print(order[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) while t > 0: t = t - 1 n, m = map(int, input().split()) s = 0 arr = [] arrm = [int(m) for m in input().split()] for i in range(n): d, v, c = map(int, input().split()) if arrm[d - 1] != 0: s = s + v arr.append(d) arrm[d - 1] = arrm[d - 1] - 1 else: s = s + c arr.append(0) print(s) arr1 = [] for i in range(m): if arrm[i] != 0: arr1.append([i + 1, arrm[i]]) j = 0 for i in range(n): if arr[i] == 0: arr[i] = arr1[j][0] arr1[j][1] = arr1[j][1] - 1 if arr1[j][1] == 0: j = j + 1 print(arr[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(t): n, m = map(int, input().strip().split(" ")) ar_m = [int(x) for x in input().split()] count = 0 ar_res = [] temp = [] q = 0 for j in range(n): d, f, b = map(int, input().strip().split(" ")) if ar_m[d - 1] != 0: count += f ar_res.append(d) ar_m[d - 1] -= 1 else: count += b temp.append(j) q += 1 k = 0 index = 0 while k != q: for j in range(index, m): if ar_m[j] != 0: ar_res.insert(temp[k], j + 1) k += 1 ar_m[j] -= 1 index = j break print(count) for j in range(n): print(ar_res[j], end=" ") print(" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(t): n, m = map(int, input().split(" ")) c = [int(j) for j in input().split(" ")] revenue = 0 finallist = [] remlist = [] p = 0 customer = [] for j in range(n): customer.append([int(j) for j in input().split(" ")]) if c[customer[j][0] - 1] > 0: revenue += customer[j][1] finallist.append(customer[j][0]) c[customer[j][0] - 1] -= 1 else: remlist.append(p) p += 1 k = 0 while len(remlist): if c[k] > 0: revenue += customer[remlist[0]][2] finallist.insert(remlist[0], k + 1) c[k] -= 1 remlist.remove(remlist[0]) else: k += 1 print(revenue) print(*finallist, sep=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) while t: t -= 1 s = 0 r = [] a = input().split() b = list(map(int, input().split())) for i in range(int(a[0])): c = list(map(int, input().split())) if b[c[0] - 1] > 0: s += c[1] b[c[0] - 1] -= 1 r += [c[0]] else: s += c[2] r += [-10] print(s) tt = 0 for i in range(int(a[0])): if r[i] != -10: print(r[i], end=" ") else: while b[tt] == 0: tt += 1 print(tt + 1, end=" ") b[tt] -= 1 print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR LIST VAR NUMBER VAR VAR NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = list(map(int, input().split())) c = list(map(int, input().split())) l = [0] * n total = 0 for i in range(n): d, f, b = list(map(int, input().split())) if c[d - 1] > 0: c[d - 1] -= 1 total += f l[i] = d else: total += b t = m - 1 print(total) for i in l: if i > 0: print(i, end=" ") else: while True: if c[t] > 0: print(t + 1, end=" ") c[t] -= 1 if c[t] == 0: t -= 1 break else: t -= 1 print("")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING WHILE NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for _ in range(t): n, m = map(int, input().split()) c = list(map(int, input().split())) l = [] k = [(0) for _ in range(n)] max_pro = 0 for i in range(n): d, f, b = map(int, input().split()) if c[d - 1] > 0: c[d - 1] -= 1 k[i] = d max_pro += f else: l.append((d, b, i)) v, j = 0, 0 while j < len(l): if c[v] == 0: v = v + 1 else: d, b, i = l[j] k[i] = v + 1 max_pro += b c[v] -= 1 j = j + 1 print(max_pro) print(*k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) s = 0 s1 = 0 ans = [] j = 0 q = [] q1 = [] p = list(map(int, input().split())) for i in p: s += i if s >= n: while n: d, f, b = map(int, input().split()) if p[d - 1] > 0: s1 += f p[d - 1] -= 1 j += 1 ans.append(d) else: s1 += b ans.append(0) q.append(j) j += 1 n -= 1 for i in range(len(p)): if p[i] != 0: q1.append([i, p[i]]) x = 0 for i in q: if q1[x][1] != 0: ans[i] = q1[x][0] + 1 q1[x][1] -= 1 else: x += 1 ans[i] = q1[x][0] + 1 q1[x][1] -= 1 print(s1) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR IF VAR VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
def get(arr, i, m): while i <= m: if arr[i] > 0: return i i += 1 for t in range(int(input())): n, m = map(int, input().split()) arr = [int(x) for x in input().split()] arr.insert(0, 0) profit = 0 res = [] for i in range(n): d, f, b = map(int, input().split()) if arr[d] > 0: profit += f arr[d] -= 1 res.append(d) else: profit += b res.append(-1) print(profit) id = 1 for i in res: if i != -1: print(i, end=" ") else: id = get(arr, id, m) print(id, end=" ") arr[id] -= 1 print()
FUNC_DEF WHILE VAR VAR IF VAR VAR NUMBER RETURN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
class Solution(object): def __init__(self): self.tests = int(input()) self.num_customers = 0 self.num_flavors = 0 self.flavors = [] self.d = [] self.f = [] self.b = [] self.ans = [] self.chosen_flavors = [] for _ in range(self.tests): self.get_data() self.solve() self.print_output() self.clear_data() pass def get_data(self): self.num_customers, self.num_flavors = map(int, input().split()) self.ans = [0] * self.num_customers self.chosen_flavors = [0] * self.num_customers self.flavors = [0] + list(map(int, input().split())) for _ in range(self.num_customers): d, f, b = map(int, input().split()) self.d.append(d) self.f.append(f) self.b.append(b) pass def clear_data(self): self.flavors.clear() self.d.clear() self.f.clear() self.b.clear() self.ans.clear() self.chosen_flavors.clear() pass def print_output(self): print(sum(self.ans)) for x in self.chosen_flavors: print(x, end=" ") pass def solve(self): for i in range(self.num_customers): if self.flavors[self.d[i]]: self.ans[i] = self.f[i] self.flavors[self.d[i]] -= 1 self.chosen_flavors[i] = self.d[i] begin = 1 for i in range(len(self.chosen_flavors)): if self.chosen_flavors[i] == 0: for j in range(begin, self.num_flavors + 1): if self.flavors[j]: self.ans[i] = self.b[i] self.flavors[j] -= 1 self.chosen_flavors[i] = j begin = j break pass def main(): Solution() pass main()
CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for i in range(int(input())): nn, m = map(int, input().split()) c = list(map(int, input().split())) d = dict() pro = 0 arr = [0] * nn k = 0 hold = [] while nn > 0: nn -= 1 l, m, n = map(int, input().split()) if c[l - 1] > 0: pro += m arr[k] = l c[l - 1] -= 1 else: pro += n hold.append(k) k += 1 cou = len(hold) for i in range(len(c)): if c[i] > 0: while c[i] > 0: c[i] -= 1 if hold == []: cou = 0 break arr[hold[0]] = i + 1 hold.pop(0) cou -= 1 if cou < 1: break if cou < 1: break print(pro) for i in range(len(arr)): print(arr[i], end=" ")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER IF VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) while t: n, m = map(int, input().split()) M = list(map(int, input().split())) profit = 0 order = [] for i in range(n): d, f, b = map(int, input().split()) if M[d - 1] > 0: M[d - 1] -= 1 profit += f order.append(d) else: profit += b order.append(0) print(profit) remaining = [] for i in range(m): if M[i] != 0: remaining.append([i, M[i]]) k = 0 for i in range(n): if order[i] != 0: print(order[i], end=" ") else: print(remaining[k][0] + 1, end=" ") remaining[k][1] -= 1 if remaining[k][1] == 0: k += 1 print() t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER STRING VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for _ in range(t): n, m = map(int, input().split()) flav = list(map(int, input().split())) ans = [] res = 0 k = 0 for i in range(n): d, f, b = map(int, input().split()) if flav[d - 1] == 0: res += b ans.append(-1) k += 1 else: flav[d - 1] -= 1 res += f ans.append(d) l = [] for i in range(m): while flav[i] != 0 and k != 0: flav[i] -= 1 k -= 1 l.append(i + 1) print(res) c = 0 for i in range(n): if ans[i] == -1: print(l[c], end=" ") c += 1 else: print(ans[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for i in range(int(input())): n, m = map(int, input().split()) l = list(map(int, input().split())) profit = 0 s = [0] * n for j in range(n): d, f, b = map(int, input().split()) d = d - 1 if l[d] > 0: profit += f l[d] -= 1 s[j] = str(d + 1) else: profit += b k = 0 for j in range(n): if s[j] == 0: while l[k] == 0: k += 1 s[j] = str(k + 1) l[k] -= 1 print(profit) k = " " print(k.join(s))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
T = int(input()) for t in range(0, T): N, M = input().split(" ") C = list(map(int, input().split())) DFB = [] profit = 0 Ccopy = C.copy() lst = [] x = [] for i in range(int(N)): DFB.append(list(map(int, input().split()))) for i in range(int(N)): if C[DFB[i][0] - 1] > 0: C[DFB[i][0] - 1] -= 1 profit += DFB[i][1] lst.append(DFB[i][0]) else: profit += DFB[i][2] lst.append(0) for i in range(int(M)): if C[i] != 0: x.append([i, C[i]]) for i in range(int(N)): if lst[i] == 0: if x[-1][1] != 0: x[-1][1] -= 1 lst[i] = x[-1][0] + 1 else: x.pop() x[-1][1] -= 1 lst[i] = x[-1][0] + 1 print(profit) print(*lst)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) av = list(map(int, input().split())) dem = {} for i in range(m): dem[i + 1] = av[i] s = 0 l = [-1] * n left = [] for i in range(n): d, f, b = map(int, input().split()) if d in dem: s += f dem[d] -= 1 l[i] = d if dem[d] == 0: del dem[d] else: s += b left.append(i) for i in left: for j in dem: l[i] = j dem[j] -= 1 if dem[j] == 0: del dem[j] break print(s) for i in l: print(i, end=" ")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(t): n, m = [int(x) for x in input().split()] amt = [int(x) for x in input().split()] cost = 0 brr = [(0) for x in range(n)] crr = [] for j in range(n): d, f, b = [int(x) for x in input().split()] if amt[d - 1] > 0: amt[d - 1] -= 1 cost += f brr[j] = d else: crr.append(j) cost += b r = 0 for j in crr: for k in range(r, m): if amt[k] > 0: r = k amt[k] -= 1 brr[j] = k + 1 break print(cost) for j in range(n - 1): print(brr[j], end=" ") print(brr[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = [int(x) for x in input().split()] c = [int(x) for x in input().split()] sum = 0 res = [] for _ in range(n): d, f, b = [int(x) for x in input().split()] if c[d - 1] > 0: c[d - 1] -= 1 sum += f res.append(d) elif c[d - 1] == 0: res.append(0) sum += b for y in range(len(c)): if c[y] != 0: m = y break for x in range(len(res)): if res[x] == 0: for y in range(m, len(c)): if c[y] > 0: res[x] = y + 1 c[y] -= 1 break else: m += 1 print(sum) l = [print(i, end=" ") for i in res]
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) count = list(map(int, input().split())) profit = 0 aux = [] ans = [0] * n for i in range(n): d, f, b = map(int, input().split()) if f >= b and count[d - 1] > 0: count[d - 1] -= 1 profit += f ans[i] = d else: aux.append((i, b)) pos = 0 for i in aux: while count[pos] == 0: pos += 1 count[pos] -= 1 profit += i[1] ans[i[0]] = pos + 1 print(profit) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) drink_freq = list(map(int, input().split())) orders = [] ans = [] money = 0 for i in range(n): d, f, b = map(int, input().split()) orders.append((d, f, b)) for j in range(n): if drink_freq[orders[j][0] - 1] != 0: money += orders[j][1] drink_freq[orders[j][0] - 1] -= 1 ans.append(orders[j][0]) else: money += orders[j][2] ans.append(-1) print(money) y = [] for l in range(len(drink_freq)): if drink_freq[l] != 0: y.append([l, drink_freq[l]]) ref = 0 for k in range(n): if ans[k] == -1: if y[ref][1] != 0: ans[k] = y[ref][0] + 1 y[ref][1] -= 1 else: ref += 1 ans[k] = y[ref][0] + 1 y[ref][1] -= 1 print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) l = list(map(int, input().split())) p = 0 o = [] x = [] for i in range(n): k = list(map(int, input().split())) if l[k[0] - 1] > 0: p += k[1] l[k[0] - 1] -= 1 o.append(k[0]) else: o.append(0) p += k[2] x.append(i) j = 0 i = 0 while i < n and j < len(x): if l[i] > 0: o[x[j]] = i + 1 l[i] -= 1 j += 1 else: i += 1 print(p) for i in o: print(i, end=" ")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) c = list(map(int, input().split())) l = [] ans = 0 for z in range(n): d, f, b = map(int, input().split()) l.append([d, f, b]) v = [0] * len(l) res = [0] * n a = [] for j, i in enumerate(l): if c[i[0] - 1] > 0: c[i[0] - 1] -= 1 ans += i[1] v[j] = 1 res[j] = i[0] s = len(l) lc = len(c) count = 0 for i in range(s): if v[i] == 0: ans += l[i][2] count += 1 k = [] for i in range(lc): if c[i] > 0: while c[i] > 0 and count > 0: c[i] -= 1 count -= 1 k.append(i + 1) kl = len(res) for i in range(kl): if res[i] == 0: res[i] = k.pop() print(ans) for i in res: print(i, end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for x in range(t): n, m = map(int, input().split()) c = list(map(int, input().split())) costs = [] total = 0 indices = [] left = [] for y in range(n): d, f, b = map(int, input().split()) if c[d - 1] > 0: c[d - 1] = c[d - 1] - 1 total = total + f costs.append(d) else: costs.append(0) indices.append([y, b]) for y in range(len(c)): if c[y] > 0: left.append([y + 1, c[y]]) x = 0 for y in range(len(indices)): if left[x][1] == 0: x = x + 1 costs[indices[y][0]] = left[x][0] left[x][1] = left[x][1] - 1 total = total + indices[y][1] print(total) print(*costs, sep=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
def solve(quantity, N, M): ans, drink = 0, [-1] * N for i in range(N): D, F, B = map(int, input().split()) if quantity[D - 1] > 0: ans += F drink[i] = D quantity[D - 1] -= 1 else: ans += B index = 0 for i in range(N): if drink[i] != -1: continue while quantity[index] == 0: index += 1 drink[i] = index + 1 quantity[index] -= 1 print(ans) for i in drink: print(i, end=" ") print() T = int(input()) for _ in range(T): N, M = map(int, input().split()) quantity = list(map(int, input().split())) solve(quantity, N, M)
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) l = list(map(int, input().split())) temp = n lol = [] profit = 0 while temp > 0: d, f, b = map(int, input().split()) if l[d - 1] > 0: profit += f l[d - 1] -= 1 lol.append(d) else: lol.append(-100) profit += b temp -= 1 print(profit) j = 0 for i in range(n): if lol[i] != -100: print(lol[i], end=" ") else: while l[j] == 0: j += 1 print(j + 1, end=" ") l[j] -= 1
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for _ in range(t): n, m = map(int, input().split()) c = [] c = list(map(int, input().split())) req = [] ans = 0 for i in range(n): d, f, b = map(int, input().split()) if c[d - 1] > 0: c[d - 1] -= 1 ans += f req.append(d) else: ans += b req.append(0) excess = [] for x in range(len(c)): if c[x] > 0: excess.append([x, c[x]]) pointer = 0 for i in range(len(req)): if req[i] == 0: if excess[pointer][1] > 0: req[i] = excess[pointer][0] + 1 excess[pointer][1] -= 1 else: pointer += 1 req[i] = excess[pointer][0] + 1 excess[pointer][1] -= 1 print(ans) print(*req)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
try: for _ in range(int(input())): n, m = map(int, input().split(" ")) ans = [(0) for i in range(n)] ans1 = 0 capacity = list(map(int, input().split(" "))) for i in range(n): d, f, b = list(map(int, input().split(" "))) if capacity[d - 1] > 0: ans1 += f ans[i] = d capacity[d - 1] -= 1 else: ans1 += b capacity = list(enumerate(capacity, 1)) capacity = filter(lambda x: x[1] > 0, capacity) capacity = list(capacity) ele = capacity[0][1] for i in range(n): if ans[i] == 0: if ele == 0: del capacity[0] ele = capacity[0][1] ans[i] = capacity[0][0] ele -= 1 print(ans1) for i in ans: print(i, end=" ") except Exception as e: pass
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(0, t): Sum = 0 freq = [] n, m = map(int, input().split()) ans = [0] * n freq = [int(x) for x in input().split()] for k in range(1, n + 1): val = list(map(int, input().split())) if freq[val[0] - 1] != 0: ans[k - 1] = val[0] Sum = Sum + val[1] freq[val[0] - 1] -= 1 else: Sum = Sum + val[2] f = 1 p = 1 while f <= m and p <= n: if ans[p - 1] == 0 and freq[f - 1] != 0: ans[p - 1] = f p += 1 freq[f - 1] -= 1 elif freq[f - 1] == 0: f += 1 else: p += 1 print(Sum) for g in ans: print(g, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for _ in range(t): n, m = map(int, input().split()) c = list(map(int, input().split())) que = [] ans = [-1] * n count = 0 for i in range(n): d, f, b = map(int, input().split()) if c[d - 1] != 0: c[d - 1] -= 1 ans[i] = d count += f else: que.append([i, b]) qptr = 0 lenq = len(que) for i in range(m): csvalue = c[i] flag = 0 if c[i] > 0: for j in range(csvalue): if qptr == lenq: flag = 1 break chotulist = que[qptr] ans[chotulist[0]] = i + 1 count += chotulist[1] qptr += 1 if qptr == lenq: flag = 1 break if flag == 1: break print(count) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
test = int(input()) for _ in range(test): n, m = map(int, input().split()) cx = list(map(int, input().split())) dx = [] fx = [] bx = [] for i in range(n): d, f, b = map(int, input().split()) dx.append(d) fx.append(f) bx.append(b) profit = 0 order = [] pending = [] for i in range(n): if cx[dx[i] - 1] > 0: cx[dx[i] - 1] -= 1 profit += fx[i] order.append(dx[i]) else: pending.append(i) profit += bx[i] order.append(0) cnt = 0 flag = 0 for i in range(m): while cx[i] > 0: if cnt == len(pending): flag = 1 break order[pending[cnt]] = i + 1 cnt += 1 cx[i] -= 1 if flag == 1: break print(profit) print(" ".join(str(x) for x in order))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for _ in range(t): n, m = map(int, input().split()) m1 = list(map(int, input().split())) d = [] f = [] b = [] res = [0] * n profit = 0 for i in range(n): d1, f1, b1 = map(int, input().split()) d.append(d1) f.append(f1) b.append(b1) x = d[i] if m1[x - 1] > 0: res[i] = x m1[x - 1] = m1[x - 1] - 1 profit = profit + f[i] else: res[i] = -100 profit = profit + b[i] print(profit) k = 0 for j in range(n): if res[j] != -100: print(res[j], end=" ") else: while m1[k] == 0: k += 1 print(k + 1, end=" ") m1[k] -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for _ in range(t): n, m = map(int, input().split()) c = [int(x) for x in input().split()] d = [] f = [] b = [] for i in range(n): a1, b1, c1 = map(int, input().split()) d.append(a1) f.append(b1) b.append(c1) mp = 0 ans = [] for i in range(n): if c[d[i] - 1] > 0: mp = mp + f[i] c[d[i] - 1] = c[d[i] - 1] - 1 ans.append(d[i]) else: mp = mp + b[i] ans.append(-1) print(mp) j = 0 for i in range(n): if ans[i] != -1: print(ans[i], end=" ") else: while c[j] == 0: j += 1 print(j + 1, end=" ") c[j] -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for e in range(int(input())): n, m = map(int, input().split()) c = list(map(int, input().split())) pf = 0 sale = [0] * n hold = [] for i in range(n): d, f, b = map(int, input().split()) if c[d - 1] != 0: sale[i] = d pf += f c[d - 1] -= 1 else: hold += [[i, b]] for i in range(m): flag = 0 if c[i] > 0: for j in range(c[i]): if hold == []: flag = 1 break sale[hold[0][0]] = i + 1 pf += hold[0][1] hold.pop(0) if flag == 1: break print(pf) print(*sale)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
T = int(input()) for t in range(T): N, M = list(map(int, input().split())) c = list(map(int, input().split())) likes = [(0) for i in range(M)] fs = [] bs = [] ds = [] for n in range(N): d, f, b = list(map(int, input().split())) ds.append(d) likes[d - 1] += 1 fs.append(f) bs.append(b) stock = [] for i in range(M): stock.append([i, c[i] - likes[i]]) stock.sort(reverse=True, key=lambda x: x[1]) profit = 0 ans = [] for i in range(N): if c[ds[i] - 1] > 0: c[ds[i] - 1] -= 1 ans.append(ds[i]) profit += fs[i] else: ans.append(stock[0][0] + 1) stock[0][1] -= 1 if stock[0][1] == 0: stock.pop(0) profit += bs[i] print(profit) print(" ".join(map(str, ans)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
try: t = int(input()) while t > 0: n, m = [int(x) for x in input().split()] cust_order = [] max_profit = 0 C = list(map(int, input().split())) for i in range(n): d, f, b = map(int, input().split()) if C[d - 1] > 0: C[d - 1] = C[d - 1] - 1 cust_order.append(d) max_profit = max_profit + f else: cust_order.append(0) max_profit = max_profit + b firs_drink = 0 for k in range(len(cust_order)): if cust_order[k] != 0: continue for l in range(firs_drink, len(C)): if C[l] > 0: cust_order[k] = l + 1 C[l] = C[l] - 1 break else: firs_drink = l + 1 print(max_profit) print(*cust_order) t = t - 1 except: pass
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = list(map(int, input().split())) c = list(map(int, input().split())) d = {} for i in range(len(c)): d[i + 1] = c[i] ans = [] profit = 0 r_1 = 0 for i in range(n): t_1, t_2, t_3 = list(map(int, input().split())) if d[t_1] > 0: profit += t_2 d[t_1] -= 1 ans.append(t_1) else: profit += t_3 r_1 += 1 ans.append("") print(profit) rem = [] for i in d: if d[i] > 0: rem += [i] * d[i] d[i] = 0 if len(rem) >= r_1: break j = 0 for i in range(len(ans)): if ans[i] == "": ans[i] = rem[j] j += 1 print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP LIST VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input().strip())): n, m = map(int, input().strip().split()) freq = [0] + list(map(int, input().strip().split())) ans = [0] * n total = 0 for i in range(n): d, f, b = map(int, input().strip().split()) if freq[d]: total += f freq[d] -= 1 ans[i] = d else: total += b ind = 0 for i in range(n): if ans[i] == 0: while freq[ind] == 0: ind += 1 ans[i] = ind freq[ind] -= 1 print(total) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) while t > 0: n, m = map(int, input().split()) a = list(map(int, input().split())) k = a.copy() c = 0 o = [] remain = [] for j in range(n): d, f, b = map(int, input().split()) if a[d - 1] > 0: c = c + f o.append(d) a[d - 1] -= 1 else: c = c + b o.append(0) remain.append(j) if k[d - 1] > 0: k[d - 1] -= 1 for j in range(len(a)): if a[j] > 0: while a[j] > 0 and remain != []: o[remain.pop()] = j + 1 a[j] -= 1 print(c) print(" ".join(map(str, o))) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): N, M = map(int, input().split()) max_av = list(map(int, input().split())) choices_and_price = [] array = [0] * M for i in range(N): a = list(map(int, input().split())) array[a[0] - 1] += 1 choices_and_price.append(a) left = [] end = {} for i in range(M): if max_av[i] > array[i]: left.append([i, max_av[i] - array[i]]) profit = 0 result_array = [] for i in range(N): p = choices_and_price[i] if max_av[p[0] - 1] > 0: max_av[p[0] - 1] -= 1 profit += p[1] result_array.append(p[0]) else: profit += p[2] k = left[0] left[0][1] -= 1 result_array.append(left[0][0] + 1) if left[0][1] == 0: left.pop(0) print(profit) print(*result_array)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
import sys input = sys.stdin.readline t = int(input()) for i in range(0, t): p = 0 h = 0 z = [] n, m = list(map(int, input().split())) a = list(map(int, input().split())) for j in range(0, n): d, c, b = list(map(int, input().split())) if a[d - 1] > 0: p = p + c z.append(d) a[d - 1] -= 1 else: p = p + b z.append(0) print(p) for j in range(0, n): if z[j] != 0: print(z[j], end=" ") else: while a[h] == 0: h += 1 print(h + 1, end=" ") a[h] -= 1
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = input() for ii in range(int(t)): n, m = map(int, input().split()) c = list(map(int, input().split())) ans = 0 remain = [] ansL = [0] * n for i in range(n): d, f, b = map(int, input().split()) if c[d - 1] > 0: c[d - 1] -= 1 ans += f ansL[i] = d else: remain.append((i, d, f, b)) j = 0 k = 0 cc = [] for i in range(len(c)): if c[i] > 0: cc.append([i + 1, c[i]]) j = 0 for i in range(len(remain)): ans += remain[i][3] ansL[remain[i][0]] = cc[j][0] cc[j][1] -= 1 if cc[j][1] == 0: j += 1 print(ans) for i in range(len(ansL)): print(ansL[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for i in range(t): n, m = map(int, input().split()) l = [0] + list(map(int, input().split())) s = 0 c = 0 m1 = [] for i in range(n): d, f, b = map(int, input().split()) if l[d] > 0: m1.append(d) s += f l[d] -= 1 else: m1.append(0) s += b for i in range(n): if m1[i] == 0: for j in range(c, m + 1): if l[j] > 0: m1[i] = j l[j] -= 1 c = j break print(s) print(*m1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, m = map(int, input().split()) drinks = list(map(int, input().split())) output = 0 remain = [] olist = [0] * n for i in range(n): demand, goodp, badp = map(int, input().split()) if drinks[demand - 1] != 0: drinks[demand - 1] -= 1 olist[i] = demand output += goodp else: remain.append(i) output += badp rj = 0 for i in range(len(drinks)): if drinks[i] == 0: continue while drinks[i] > 0: if rj == len(remain): break olist[remain[rj]] = i + 1 rj += 1 drinks[i] -= 1 if rj == len(remain): break print(output) for i in olist: print(i, end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for _ in range(int(input())): n, ml = [int(x) for x in input().split()] m = [int(x) for x in input().split()] prof = 0 remc = 0 ans = ["-"] * n for i in range(n): d, f, b = [int(x) for x in input().split()] if m[d - 1]: m[d - 1] -= 1 ans[i] = d prof += f else: prof += b remc += 1 remd = [] for i in range(ml): if m[i]: remd.extend([i + 1] * m[i]) if len(remd) >= remc: break i = 0 for j in range(n): if ans[j] == "-": ans[j] = remd[i] i += 1 print(prof) print(" ".join([str(x) for x in ans]))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
x = int(input()) for __ in range(x): a, b = map(int, input().split()) c = list(map(int, input().split())) l = [] for __ in range(a): l.append(list(map(int, input().split()))) k = 0 w = [0] * a s = 0 q = [] for i in range(len(l)): if c[l[i][0] - 1] > 0: k += l[i][1] c[l[i][0] - 1] -= 1 w[i] = l[i][0] else: k += l[i][2] s += 1 q.append(i) p = 0 while s > 0: while c[p] == 0: p += 1 c[p] -= 1 w[q[len(q) - 1 - s]] = p + 1 s -= 1 print(k) print(*w)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
for t in range(int(input())): n, m = [int(j) for j in input().split()] c = [int(j) for j in input().split()] demand_supply = dict() for i in range(m): demand_supply[i] = -1 * c[i] flav = [] F = [] B = [] for i in range(n): d, f, b = [int(j) for j in input().split()] F.append(f) B.append(b) flav.append(d - 1) ans = 0 l = [] flag = [] for i in range(n): if c[flav[i]] > 0: l.append(flav[i]) ans += F[i] c[flav[i]] -= 1 else: l.append(0) ans += B[i] flag.append(i) ct = 0 for i in c: while i > 0 and flag: l[flag[0]] = ct i -= 1 flag = flag[1:] ct += 1 print(ans) for i in l: print(i + 1, end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
def maximize(n, m, c, u): sum = 0 g = [0] * n r = [] for i in range(n): if c[u[i][0] - 1] > 0: c[u[i][0] - 1] -= 1 sum += u[i][1] g[i] = u[i][0] else: r.append(i) sum += u[i][2] ri = 0 rn = len(r) for i in range(m): if ri == rn: break else: while c[i] > 0: if ri == rn: break else: c[i] -= 1 g[r[ri]] = i + 1 ri += 1 print(sum) for i, gi in enumerate(g): if i < n - 1: print(gi, end=" ") else: print(gi) t = 0 try: t = int(input()) except: pass while t > 0: n, m = list(map(int, input().rstrip().split())) c = list(map(int, input().rstrip().split())) u = [] for i in range(n): u.append(list(map(int, input().rstrip().split()))) maximize(n, m, c, u) t -= 1
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
def m(): t = int(input()) while t > 0: n, m = map(int, input().split()) flavours = list(map(int, input().split())) count = 0 contents = [] final = [] ind = [] for i in range(n): a = list(map(int, input().split())) contents.append(a) cost = 0 for i in range(n): if flavours[contents[i][0] - 1] != 0: cost += contents[i][1] flavours[contents[i][0] - 1] -= 1 final.append(contents[i][0]) elif flavours[contents[i][0] - 1] == 0: cost += contents[i][2] count += 1 final.append("x") ind.append(i) j = 0 for i in range(count): while j < m: if flavours[j] == 0: j += 1 elif flavours[j] != 0: flavours[j] -= 1 final[ind[i]] = j + 1 break print(cost) for i in range(n): print(final[i], end=" ") t -= 1 m()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
while True: try: for _ in range(int(input())): n, m = map(int, input().split()) max_flavours = list(map(int, input().split())) people = [] for i in range(n): people.append([i + 1] + list(map(int, input().split()))) extra_flavors = [(0) for i in range(m)] for person, favorite, favMoney, nonFavMoney in people: extra_flavors[favorite - 1] += 1 remainingFlavours = [] for i in range(m): extra_flavors[i] = max_flavours[i] - extra_flavors[i] remainingFlavours.append([i + 1, extra_flavors[i]]) _extra_flavours = sorted( remainingFlavours, reverse=True, key=lambda x: x[1] ) profit = 0 answer = [] currentExtra = 0 for person, favorite, favMoney, nonFavMoney in people: if max_flavours[favorite - 1] > 0: profit += favMoney answer.append(favorite) max_flavours[favorite - 1] -= 1 else: profit += nonFavMoney if _extra_flavours[currentExtra][1] == 0: currentExtra += 1 answer.append(_extra_flavours[currentExtra][0]) _extra_flavours[currentExtra][1] -= 1 else: answer.append(_extra_flavours[currentExtra][0]) _extra_flavours[currentExtra][1] -= 1 print(profit) print(*answer) except (ValueError, EOFError) as e: break
WHILE NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
T = int(input()) for _ in range(T): N, M = map(int, input().split()) C = list(map(int, input().split())) ans = [0] * N delay = [] D = [0] * N F = [0] * N B = [0] * N sm = 0 for i in range(N): D[i], F[i], B[i] = map(int, input().split()) if C[D[i] - 1] != 0: sm += F[i] ans[i] = D[i] C[D[i] - 1] -= 1 else: delay.append(i) k = 0 i = 0 while i < len(delay): for k in range(len(C)): if i >= len(delay): break if C[k] == 0: continue else: for fug in range(C[k]): if i >= len(delay): break ans[delay[i]] = k + 1 sm += B[delay[i]] i += 1 print(sm) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink: - if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour - otherwise, Chef must sell this customer a drink, but he may choose its flavour Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $M$. - The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$. -----Output----- For each test case, print two lines: - The first of these lines should contain a single integer β€” the maximum profit. - The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order. If there are multiple solutions, you may find any one. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N, M \le 10^5$ - $1 \le D_i \le M$ for each valid $i$ - $1 \le C_i \le N$ for each valid $i$ - $1 \le B_i < F_i \le 10^9$ for each valid $i$ - $C_1+C_2+\ldots+C_M \ge N$ - the sum of $N$ over all test cases does not exceed $10^6$ - the sum of $M$ over all test cases does not exceed $10^6$ -----Example Input----- 1 5 3 1 2 3 2 6 3 2 10 7 2 50 3 1 10 5 1 7 4 -----Example Output----- 33 2 2 3 1 3
t = int(input()) for x in range(t): inp = list(map(int, input().split())) n = inp[0] m = inp[1] d = [] f = [] b = [] answer = [] profit = 0 number = list(map(int, input().split())) for i in range(n): flavor = list(map(int, input().split())) d.append(flavor[0]) f.append(flavor[1]) b.append(flavor[2]) for cust in range(n): if number[d[cust] - 1] > 0: answer.append(d[cust]) number[d[cust] - 1] -= 1 profit += f[cust] else: answer.append(0) for j in range(len(number)): if number[j] > 0: break for index in range(len(answer)): if answer[index] == 0: answer[index] = j + 1 number[j] -= 1 profit += b[index] if number[j] == 0: while number[j] == 0: j += 1 if j == m: break print(profit) print(*answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a permutation: an array $a = [a_1, a_2, \ldots, a_n]$ of distinct integers from $1$ to $n$. The length of the permutation $n$ is odd. You need to sort the permutation in increasing order. In one step, you can choose any prefix of the permutation with an odd length and reverse it. Formally, if $a = [a_1, a_2, \ldots, a_n]$, you can choose any odd integer $p$ between $1$ and $n$, inclusive, and set $a$ to $[a_p, a_{p-1}, \ldots, a_1, a_{p+1}, a_{p+2}, \ldots, a_n]$. Find a way to sort $a$ using no more than $\frac{5n}{2}$ reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($3 \le n \le 2021$; $n$ is odd) β€” the length of the permutation. The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) β€” the permutation itself. It is guaranteed that the sum of $n$ over all test cases does not exceed $2021$. -----Output----- For each test case, if it's impossible to sort the given permutation in at most $\frac{5n}{2}$ reversals, print a single integer $-1$. Otherwise, print an integer $m$ ($0 \le m \le \frac{5n}{2}$), denoting the number of reversals in your sequence of steps, followed by $m$ integers $p_i$ ($1 \le p_i \le n$; $p_i$ is odd), denoting the lengths of the prefixes of $a$ to be reversed, in chronological order. Note that $m$ doesn't have to be minimized. If there are multiple answers, print any. -----Examples----- Input 3 3 1 2 3 5 3 4 5 2 1 3 2 1 3 Output 4 3 3 3 3 2 3 5 -1 -----Note----- In the first test case, the permutation is already sorted. Any even number of reversals of the length $3$ prefix doesn't change that fact. In the second test case, after reversing the prefix of length $3$ the permutation will change to $[5, 4, 3, 2, 1]$, and then after reversing the prefix of length $5$ the permutation will change to $[1, 2, 3, 4, 5]$. In the third test case, it's impossible to sort the permutation.
t = int(input()) for tc in range(t): n = int(input()) row = list(map(int, input().split())) rowsort = sorted(row)[::-1] permutable = True for i in range(n): if (i - row[i]) % 2 == 0: permutable = False break if not permutable: print(-1) else: ret = [] for i in range(int(n / 2)): rowi = row.index(n - 2 * i) if rowi != 0: ret.append(rowi + 1) row = row[rowi::-1] + row[rowi + 1 :] rowi = row.index(n - 2 * i - 1) if rowi != 1: ret.append(rowi) ret.append(rowi + 2) ret.append(3) row = [row[0], row[rowi], row[rowi + 1]] + row[1:rowi] + row[rowi + 2 :] ret.append(n - 2 * i) row = row[n - 2 * i - 1 :: -1] + row[n - 2 * i :] print(len(ret)) print(" ".join(list(map(str, ret))))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a permutation: an array $a = [a_1, a_2, \ldots, a_n]$ of distinct integers from $1$ to $n$. The length of the permutation $n$ is odd. You need to sort the permutation in increasing order. In one step, you can choose any prefix of the permutation with an odd length and reverse it. Formally, if $a = [a_1, a_2, \ldots, a_n]$, you can choose any odd integer $p$ between $1$ and $n$, inclusive, and set $a$ to $[a_p, a_{p-1}, \ldots, a_1, a_{p+1}, a_{p+2}, \ldots, a_n]$. Find a way to sort $a$ using no more than $\frac{5n}{2}$ reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($3 \le n \le 2021$; $n$ is odd) β€” the length of the permutation. The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) β€” the permutation itself. It is guaranteed that the sum of $n$ over all test cases does not exceed $2021$. -----Output----- For each test case, if it's impossible to sort the given permutation in at most $\frac{5n}{2}$ reversals, print a single integer $-1$. Otherwise, print an integer $m$ ($0 \le m \le \frac{5n}{2}$), denoting the number of reversals in your sequence of steps, followed by $m$ integers $p_i$ ($1 \le p_i \le n$; $p_i$ is odd), denoting the lengths of the prefixes of $a$ to be reversed, in chronological order. Note that $m$ doesn't have to be minimized. If there are multiple answers, print any. -----Examples----- Input 3 3 1 2 3 5 3 4 5 2 1 3 2 1 3 Output 4 3 3 3 3 2 3 5 -1 -----Note----- In the first test case, the permutation is already sorted. Any even number of reversals of the length $3$ prefix doesn't change that fact. In the second test case, after reversing the prefix of length $3$ the permutation will change to $[5, 4, 3, 2, 1]$, and then after reversing the prefix of length $5$ the permutation will change to $[1, 2, 3, 4, 5]$. In the third test case, it's impossible to sort the permutation.
for _ in range(int(input())): n = int(input()) A = [0] + list(map(int, input().split())) for i in range(1, n + 1): if i % 2 != A[i] % 2: print(-1) break else: ans = [] def rev(x): A[1 : x + 1] = A[1 : x + 1][::-1] ans.append(x) for x in range(n, 1, -2): i = A.index(x) rev(i) j = A.index(x - 1) rev(j - 1) rev(j + 1) rev(3) rev(x) print(len(ans)) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a permutation: an array $a = [a_1, a_2, \ldots, a_n]$ of distinct integers from $1$ to $n$. The length of the permutation $n$ is odd. You need to sort the permutation in increasing order. In one step, you can choose any prefix of the permutation with an odd length and reverse it. Formally, if $a = [a_1, a_2, \ldots, a_n]$, you can choose any odd integer $p$ between $1$ and $n$, inclusive, and set $a$ to $[a_p, a_{p-1}, \ldots, a_1, a_{p+1}, a_{p+2}, \ldots, a_n]$. Find a way to sort $a$ using no more than $\frac{5n}{2}$ reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($3 \le n \le 2021$; $n$ is odd) β€” the length of the permutation. The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) β€” the permutation itself. It is guaranteed that the sum of $n$ over all test cases does not exceed $2021$. -----Output----- For each test case, if it's impossible to sort the given permutation in at most $\frac{5n}{2}$ reversals, print a single integer $-1$. Otherwise, print an integer $m$ ($0 \le m \le \frac{5n}{2}$), denoting the number of reversals in your sequence of steps, followed by $m$ integers $p_i$ ($1 \le p_i \le n$; $p_i$ is odd), denoting the lengths of the prefixes of $a$ to be reversed, in chronological order. Note that $m$ doesn't have to be minimized. If there are multiple answers, print any. -----Examples----- Input 3 3 1 2 3 5 3 4 5 2 1 3 2 1 3 Output 4 3 3 3 3 2 3 5 -1 -----Note----- In the first test case, the permutation is already sorted. Any even number of reversals of the length $3$ prefix doesn't change that fact. In the second test case, after reversing the prefix of length $3$ the permutation will change to $[5, 4, 3, 2, 1]$, and then after reversing the prefix of length $5$ the permutation will change to $[1, 2, 3, 4, 5]$. In the third test case, it's impossible to sort the permutation.
import sys input = sys.stdin.readline def swap(s): for i in range(s // 2): a[i], a[s - i - 1] = a[s - i - 1], a[i] p.append(s) return t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) m = 0 for i in range(n): if not a[i] % 2 ^ i % 2: m = -1 break if m == -1: print(m) continue p = [] for i in range(n // 2): x, y = a.index(2 * i + 1), a.index(2 * i + 2) if x > y: swap(x + 1) y = x + 1 - y - 1 swap(y) x = y - 1 swap(n - 2 * i) x, y = n - 2 * i - x - 1, n - 2 * i - y - 1 swap(x + 1) swap(n - 2 * i) else: swap(x + 1) swap(y) swap(n - 2 * i) swap(n - y + 1 - 2 * i) swap(n - 2 * i) swap(n) m = len(p) print(m) print(*p)
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a permutation: an array $a = [a_1, a_2, \ldots, a_n]$ of distinct integers from $1$ to $n$. The length of the permutation $n$ is odd. You need to sort the permutation in increasing order. In one step, you can choose any prefix of the permutation with an odd length and reverse it. Formally, if $a = [a_1, a_2, \ldots, a_n]$, you can choose any odd integer $p$ between $1$ and $n$, inclusive, and set $a$ to $[a_p, a_{p-1}, \ldots, a_1, a_{p+1}, a_{p+2}, \ldots, a_n]$. Find a way to sort $a$ using no more than $\frac{5n}{2}$ reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($3 \le n \le 2021$; $n$ is odd) β€” the length of the permutation. The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) β€” the permutation itself. It is guaranteed that the sum of $n$ over all test cases does not exceed $2021$. -----Output----- For each test case, if it's impossible to sort the given permutation in at most $\frac{5n}{2}$ reversals, print a single integer $-1$. Otherwise, print an integer $m$ ($0 \le m \le \frac{5n}{2}$), denoting the number of reversals in your sequence of steps, followed by $m$ integers $p_i$ ($1 \le p_i \le n$; $p_i$ is odd), denoting the lengths of the prefixes of $a$ to be reversed, in chronological order. Note that $m$ doesn't have to be minimized. If there are multiple answers, print any. -----Examples----- Input 3 3 1 2 3 5 3 4 5 2 1 3 2 1 3 Output 4 3 3 3 3 2 3 5 -1 -----Note----- In the first test case, the permutation is already sorted. Any even number of reversals of the length $3$ prefix doesn't change that fact. In the second test case, after reversing the prefix of length $3$ the permutation will change to $[5, 4, 3, 2, 1]$, and then after reversing the prefix of length $5$ the permutation will change to $[1, 2, 3, 4, 5]$. In the third test case, it's impossible to sort the permutation.
import sys input = sys.stdin.readline def main(): n = int(input()) alst = list(map(int, input().split())) pos = [-1] * n for i, a in enumerate(alst): a -= 1 alst[i] -= 1 if (a - i) % 2 == 1: print(-1) return pos[a] = i ans = [] for i in range(n - 1, 0, -2): p = pos[i] ans.append(p + 1) for j in range(p // 2): alst[j], alst[p - j] = alst[p - j], alst[j] pos[alst[j]], pos[alst[p - j]] = pos[alst[p - j]], pos[alst[j]] p = pos[i - 1] ans.append(p) p -= 1 for j in range(p // 2): alst[j], alst[p - j] = alst[p - j], alst[j] pos[alst[j]], pos[alst[p - j]] = pos[alst[p - j]], pos[alst[j]] ans.append(p + 3) p += 2 for j in range(p // 2): alst[j], alst[p - j] = alst[p - j], alst[j] pos[alst[j]], pos[alst[p - j]] = pos[alst[p - j]], pos[alst[j]] p = 2 ans.append(3) for j in range(p // 2): alst[j], alst[p - j] = alst[p - j], alst[j] pos[alst[j]], pos[alst[p - j]] = pos[alst[p - j]], pos[alst[j]] p = i ans.append(p + 1) for j in range(p // 2): alst[j], alst[p - j] = alst[p - j], alst[j] pos[alst[j]], pos[alst[p - j]] = pos[alst[p - j]], pos[alst[j]] print(len(ans)) print(*ans) for _ in range(int(input())): main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You have a permutation: an array $a = [a_1, a_2, \ldots, a_n]$ of distinct integers from $1$ to $n$. The length of the permutation $n$ is odd. You need to sort the permutation in increasing order. In one step, you can choose any prefix of the permutation with an odd length and reverse it. Formally, if $a = [a_1, a_2, \ldots, a_n]$, you can choose any odd integer $p$ between $1$ and $n$, inclusive, and set $a$ to $[a_p, a_{p-1}, \ldots, a_1, a_{p+1}, a_{p+2}, \ldots, a_n]$. Find a way to sort $a$ using no more than $\frac{5n}{2}$ reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($3 \le n \le 2021$; $n$ is odd) β€” the length of the permutation. The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) β€” the permutation itself. It is guaranteed that the sum of $n$ over all test cases does not exceed $2021$. -----Output----- For each test case, if it's impossible to sort the given permutation in at most $\frac{5n}{2}$ reversals, print a single integer $-1$. Otherwise, print an integer $m$ ($0 \le m \le \frac{5n}{2}$), denoting the number of reversals in your sequence of steps, followed by $m$ integers $p_i$ ($1 \le p_i \le n$; $p_i$ is odd), denoting the lengths of the prefixes of $a$ to be reversed, in chronological order. Note that $m$ doesn't have to be minimized. If there are multiple answers, print any. -----Examples----- Input 3 3 1 2 3 5 3 4 5 2 1 3 2 1 3 Output 4 3 3 3 3 2 3 5 -1 -----Note----- In the first test case, the permutation is already sorted. Any even number of reversals of the length $3$ prefix doesn't change that fact. In the second test case, after reversing the prefix of length $3$ the permutation will change to $[5, 4, 3, 2, 1]$, and then after reversing the prefix of length $5$ the permutation will change to $[1, 2, 3, 4, 5]$. In the third test case, it's impossible to sort the permutation.
from sys import stdin, stdout def solve(n, a_a): p_a = [-1] * n for i in range(n): a_a[i] -= 1 p_a[a_a[i]] = i if a_a[i] % 2 != i % 2: return [-1] res = [] for i in range(n // 2, 0, -1): cur = i * 2 res.append(p_a[cur] + 1) reverse(a_a, p_a, p_a[cur]) res.append(p_a[cur - 1]) reverse(a_a, p_a, p_a[cur - 1] - 1) res.append(p_a[cur - 1] + 2) reverse(a_a, p_a, p_a[cur - 1] + 1) res.append(p_a[cur] + 1) reverse(a_a, p_a, p_a[cur]) res.append(cur + 1) reverse(a_a, p_a, cur) return [len(res), res] def reverse(a_a, p_a, i): l = 0 r = i while l < r: swap(a_a, l, r) swap(p_a, a_a[l], a_a[r]) l += 1 r -= 1 def swap(a_a, i, j): tmp = a_a[i] a_a[i] = a_a[j] a_a[j] = tmp t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) a_a = list(map(int, stdin.readline().split())) res = solve(n, a_a) stdout.write(str(res[0]) + "\n") if res[0] > 0: stdout.write(" ".join(map(str, res[1])) + "\n")
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN LIST FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER STRING
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
from sys import stdin def updiv(a, b): if a % b == 0: return a // b else: return a // b + 1 tt = int(stdin.readline()) for loop in range(tt): n, k = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) num = 0 for i in range(n): if i == 0: num += 1 elif a[i] != a[i - 1]: num += 1 if k == 1: if num == 1: print(1) else: print(-1) continue elif num <= k: print(1) continue num -= k print(updiv(num, k - 1) + 1)
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
testCases = int(input()) for j in range(0, testCases): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] if k == 1: allEqual = True for i in range(0, n): if a[i] != a[0]: allEqual = False if allEqual: print(1) else: print(-1) continue different = 1 arrayCount = 1 numsNeeded = k for i in range(1, n): if a[i] != a[i - 1]: different += 1 if different > numsNeeded: arrayCount += 1 different = 1 numsNeeded = k - 1 print(arrayCount)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = map(int, input().split()) A = len(set(list(map(int, input().split())))) if k != 1: print(max(0, (A - 2) // (k - 1)) + 1) elif A != 1: print(-1) else: print(1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = map(int, input().split()) l = set(map(int, input().split())) if len(l) == 1: print(1) elif k == 1: print(-1) else: print((len(l) - 2 + (k - 1)) // (k - 1))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys input = sys.stdin.readline def main(): n, k = map(int, input().split()) alst = list(map(int, input().split())) if k == 1: if alst[0] == alst[-1]: print(1) else: print(-1) return cnt = 0 bef = alst[0] for a in alst[1:]: if bef != a: cnt += 1 bef = a k -= 1 ans = (cnt + k - 1) // k print(max(ans, 1)) for _ in range(int(input())): main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
t = int(input()) for nbt in range(t): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] nbc = len(set(a)) - 1 if k == 1: if nbc: print(-1) else: print(1) else: print(1 + max(0, (nbc - 1) // (k - 1)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
t = int(input()) for i in range(t): n, k = input().strip().split(" ") n, k = [int(n), int(k)] a = list(map(int, input().strip().split(" "))) p = list(set(a)) if k == 1 and len(p) > 1: print(-1) elif k == 1 and len(p) == 1: print(1) else: ff = len(p) ff -= k ans = 1 if ff <= 0: print(ans) else: if ff % (k - 1): ans += ff // (k - 1) + 1 else: ans += ff // (k - 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for __ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) h = len(set(a)) count = 0 if k == 1: if h == 1: print(1) else: print(-1) else: for i in range(0, n - 1): if a[i + 1] - a[i] != 0: count += 1 if count == 0: print(1) elif count % (k - 1) != 0: print(count // (k - 1) + 1) else: print(count // (k - 1))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = map(int, input().split()) diff = 0 last = next(a) for v in a: if last != v: diff += 1 last = v if k == 1: if diff: print(-1) else: print(1) else: print(max(1, (diff + k - 2) // (k - 1)))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) cnt = 0 ans = 0 check = False if k == 1 and a.count(a[0]) != n: print("-1") continue elif k == 1 and a.count(a[0]) == n: print(1) continue while sum(a) != 0: ans += 1 cr = a[0] cnt = 1 ind = 0 a[0] = 0 for i in range(1, n): if a[i] != cr and cnt < k: cnt += 1 cr = a[i] a[i] = 0 else: a[i] -= cr print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) d = 1 for i in range(1, n): if a[i] != a[i - 1]: d += 1 if k == 1 and d > 1: print(-1) elif k == 1 and d == 1 or d <= k: print(1) else: print(1 + (d - k) // (k - 1) + 1 * ((d - k) % (k - 1) != 0))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = map(int, input().split()) elems = len(set([*map(int, input().split())])) if k == 1 and elems > 1: print(-1) elif k >= elems: print(1) else: print(max(1, (elems - 1 + k - 2) // (k - 1)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys input = sys.stdin.buffer.readline for _ in range(int(input())): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] rem = a[:] if len(set(a)) <= k: print(1) elif k == 1: print(-1) else: print((len(set(a)) - 1 + k - 2) // (k - 1))
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
from sys import stdin, stdout for _ in range(int(stdin.readline())): n, k = list(map(int, stdin.readline().split())) a = list(map(int, stdin.readline().split())) dist = len(set(a)) if k == 1 and dist > 1: print(-1) continue op = 0 while a[-1] != 0: new = [a[0]] dist = 1 op += 1 for v in a[1:]: if dist + 1 > k: break new += [v] if new and new[-1] != new[-2]: dist += 1 while len(new) != n: new += [new[-1]] for i in range(n): a[i] -= new[i] print(op)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR LIST VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) count = 1 for i in range(1, n): if a[i] != a[i - 1]: count += 1 if count == 1: print(1) elif k == 1: print(-1) elif (count - 1) % (k - 1) == 0: print((count - 1) // (k - 1)) else: print((count - 1) // (k - 1) + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n, k = map(int, input().split()) A = list(map(int, input().split())) k1 = 0 B = [(0) for i in range(101)] for i in A: if B[i] == 0: k1 = k1 + 1 B[i] = 1 if k >= k1: print(1) elif k == 1: print(-1) else: ans = 1 val = k1 - k ans = ans + val // (k - 1) if val % (k - 1) != 0: ans = ans + 1 print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) s = set(a) n1 = len(s) if len(s) == 1: print(1) continue if k == 1 and n1 > 1: print(-1) else: for i in range(1000): if k * i - (i - 1) >= n1: print(i) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, k = map(int, input().split()) nList = list(map(int, input().rstrip().split())) ans = 0 l = len(set(nList)) if k == 1: if l != 1: print(-1) if l == 1: print(1) else: ans = 1 l = l - k if l <= 0: print(ans) continue while True: l = l - (k - 1) ans += 1 if l <= 0: print(ans) break
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N, K = map(int, input().split()) C = len(list(set([int(a) for a in input().split()]))) if C <= K: print(1) elif K == 1: print(-1) else: print((C - 1 + K - 2) // (K - 1))
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
y = lambda: [*map(int, input().split())] for _ in range(int(input())): n, k = map(int, input().split()) a = y() b = len(set(a)) if k < 2: print(1 - 2 * (b > 1)) else: print(max(1, -((1 - b) // (k - 1))))
ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in " " * int(input()): n, k = map(int, input().split()) a = list(map(int, input().split())) if len(set(a)) > 1 and k == 1: print(-1) elif len(set(a)) <= k: print(1) else: print(1 + (len(set(a)) - 2) // (k - 1))
FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys readline = sys.stdin.readline T = int(readline()) Ans = [None] * T for qu in range(T): N, K = list(map(int, readline().split())) A = list(map(int, readline().split())) if K == 1: if len(set(A)) == 1: Ans[qu] = 1 else: Ans[qu] = -1 else: s = len(set(A)) if K >= s: Ans[qu] = 1 else: Ans[qu] = 1 - (K - s) // (K - 1) print("\n".join(map(str, Ans)))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
gans = [] for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) u = [] for i in range(1, n): if a[i] == a[i - 1]: continue u.append(a[i - 1]) u.append(a[-1]) if len(u) > 1 and k == 1: ans = -1 elif k == 1: ans = 1 elif len(u) == 1: ans = 1 else: ans = max(len(u) - 1 - 1, 0) // (k - 1) + 1 gans.append(ans) print("\n".join(map(str, gans)))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) arr = list(map(int, input().split())) s = set(arr) l = len(s) if k == 1: if l > 1: print(-1) else: print(1) elif l <= k: print(1) elif (l - k) % (k - 1) == 0: print(1 + (l - k) // (k - 1)) else: print(2 + (l - k) // (k - 1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): [n, k] = list(map(int, input().split())) arr = list(map(int, input().split())) output = 0 if k == 1: if len(set(arr)) > 1: print(-1) else: print(1) else: j = len(set(arr)) j -= k output += 1 if j > 0: output += j // (k - 1) if j % (k - 1) != 0: output += 1 print(output)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = a[0] c = 1 d = [a[0]] for i in a: if i == b: b = i else: c += 1 d += [i] b = i if c <= k: print(1) continue hjo = 0 for m in range(2, n + 1): if 2 + (c - 2) // m <= k: print(m) hjo = 1 break if hjo != 1: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR LIST VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
from sys import stdin, stdout input = stdin.readline print = lambda x: stdout.write(str(x) + "\n") for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) if k == 1: if len(set(a)) == 1: print(1) else: print(-1) continue m = 0 while a[-1]: d = 1 ld = a[0] a[0] = 0 for i in range(1, n): if ld == a[i]: a[i] -= ld elif d < k: ld = a[i] a[i] = 0 d += 1 else: a[i] -= ld m += 1 print(m)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
t = int(input()) while t > 0: t -= 1 n, k = map(int, input().split()) l = list(map(int, input().split())) d = 0 for i in range(n - 1): if l[i] < l[i + 1]: d += 1 if d == 0: print(1) elif k == 1: print(-1) else: print(int((d + k - 2) / (k - 1)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys as _sys def main(): t = int(input()) for i_t in range(t): n, k = _read_ints() a = tuple(_read_ints()) try: result = find_min_m(a, k) except ValueError: result = -1 print(result) def _read_line(): result = _sys.stdin.readline() assert result[-1] == "\n" return result[:-1] def _read_ints(): return map(int, _read_line().split(" ")) def find_min_m(a_seq, k): assert k >= 1 a_seq = tuple(a_seq) if a_seq.count(0) == len(a_seq): return 0 steps_n = sum(x1 != x2 for x1, x2 in zip(a_seq, a_seq[1:])) if k == 1: if steps_n == 0: return 1 else: raise ValueError("can't find min m") result = 0 steps_per_b_seq = k - 1 if a_seq[0] != 0: steps_n += 1 if steps_n <= k: return 1 steps_n -= k result += 1 result += _ceil_div(steps_n, steps_per_b_seq) return result def _ceil_div(x, y): assert y > 0 result = x // y if x % y != 0: result += 1 return result main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER STRING RETURN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def gift(): for _ in range(t): n, k = list(map(int, input().split())) array = list(map(int, input().split())) diff = 0 for i in range(1, n): if array[i] > array[i - 1]: diff += 1 if k == 1: if diff > 0: yield -1 else: yield 1 elif diff == 0: yield 1 elif diff % (k - 1): yield diff // (k - 1) + 1 else: yield diff // (k - 1) t = int(input()) ans = gift() print(*ans, sep="\n")
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR NUMBER EXPR NUMBER IF VAR NUMBER EXPR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER EXPR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
def solve(): case = int(input()) for _case in range(case): n, k = map(int, input().split()) li = list(map(int, input().split())) number = 1 for i in range(1, n): if li[i] != li[i - 1]: number += 1 if number == 1: print(1) elif k == 1: print(-1) else: print((number - 2) // (k - 1) + 1) solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
cases = int(input()) for t in range(cases): n, k = list(map(int, input().split())) a = list(map(int, input().split())) v1 = sorted(list(set(a))) vl = len(v1) if k == 1 and vl != 1: print(-1) else: m = 1 while vl > k: a = [(i if i > v1[k - 1] else 0) for i in a] v1 = sorted(list(set(a))) vl = len(v1) m += 1 print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
for _ in range(int(input())): n, k = list(map(int, input().split())) arr = list(map(int, input().split())) arr.sort() temp = [arr[i] for i in range(n)] last = [(0) for i in range(n)] cnt = 0 while arr != last: mex = arr[0] uni = 1 arr[0] = 0 for i in range(1, n): if arr[i] == mex: arr[i] = 0 elif uni < k: mex = arr[i] uni += 1 arr[i] = 0 else: arr[i] -= mex cnt += 1 if arr == temp: cnt = -1 break else: temp = [arr[i] for i in range(n)] print(cnt)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$. You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that: The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$. For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$. The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. Find the minimum possible value of $m$, or report that there is no possible $m$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases. The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$). -----Output----- For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$. -----Example----- Input 6 4 1 0 0 0 1 3 1 3 3 3 11 3 0 1 2 2 3 3 3 4 4 4 4 5 3 1 2 3 4 5 9 4 2 2 3 5 7 11 13 13 17 10 7 0 1 1 2 3 3 4 5 5 6 Output -1 1 2 2 2 1 -----Note----- In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros. In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$. In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.
def readis(): return map(int, input().strip().split()) def printlist(xs): print(" ".join(map(str, xs))) T = int(input()) while T: T -= 1 n, k = readis() A = list(readis()) n_uniq = len(set(A)) if k == 1: if n_uniq == 1: print(1) else: print(-1) else: print(1 + max(n_uniq - k + k - 2, 0) // (k - 1))
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER