message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Grisha come to a contest and faced the following problem. You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q operations on the array. The i-th operation is described with three integers l_i, r_i and x_i (1 ≀ l_i ≀ r_i ≀ n, 1 ≀ x_i ≀ n) and means that you should add x_i to each of the elements with indices l_i, l_i + 1, …, r_i. After all operations you should find the maximum in the array. Grisha is clever, so he solved the problem quickly. However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?" Help Grisha, find all integers y between 1 and n such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to y. Input The first line contains two integers n and q (1 ≀ n, q ≀ 10^{4}) β€” the length of the array and the number of queries in the initial problem. The following q lines contain queries, one per line. The i-th of these lines contains three integers l_i, r_i and x_i (1 ≀ l_i ≀ r_i ≀ n, 1 ≀ x_i ≀ n), denoting a query of adding x_i to the segment from l_i-th to r_i-th elements of the array, inclusive. Output In the first line print the only integer k, denoting the number of integers from 1 to n, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations. In the next line print these k integers from 1 to n β€” the possible values of the maximum. Print these integers in increasing order. Examples Input 4 3 1 3 1 2 4 2 3 4 4 Output 4 1 2 3 4 Input 7 2 1 5 1 3 7 2 Output 3 1 2 3 Input 10 3 1 1 2 1 1 3 1 1 6 Output 6 2 3 5 6 8 9 Note Consider the first example. If you consider the subset only of the first query, the maximum is equal to 1. If you take only the second query, the maximum equals to 2. If you take the first two queries, the maximum becomes 3. If you take only the fourth query, the maximum becomes 4. If you take the fourth query and something more, the maximum becomes greater that n, so you shouldn't print it. In the second example you can take the first query to obtain 1. You can take only the second query to obtain 2. You can take all queries to obtain 3. In the third example you can obtain the following maximums: * You can achieve the maximim of 2 by using queries: (1). * You can achieve the maximim of 3 by using queries: (2). * You can achieve the maximim of 5 by using queries: (1, 2). * You can achieve the maximim of 6 by using queries: (3). * You can achieve the maximim of 8 by using queries: (1, 3). * You can achieve the maximim of 9 by using queries: (2, 3). Submitted Solution: ``` [n, q] = [int(x) for x in input().split()] plus, minus = [[] for x in range(n + 1)], [[] for x in range(n + 1)] ok, dp = [0] * (n + 1), [0] * (n + 1) for i in range(q): [L, R, val] = [int(x) for x in input().split()] plus[L].append(val) minus[R].append(val) def Plus(v): for i in range(n, v - 1, -1): dp[i] += dp[i - v] def Minus(v): for i in range(v, n + 1): dp[i] -= dp[i - v] dp[0] = 1 for i in range(1, n + 1): for j in plus[i]: Plus(j) for j in range(1, n + 1): ok[j] = max(ok[j], dp[j]) for j in minus[i]: Minus(j) ans = [] for i in range(1, n + 1): if ok[i] > 0: print(i, ok[i]) ans.append(i) print(len(ans)) print(' '.join([str(x) for x in ans])) ```
instruction
0
94,129
12
188,258
No
output
1
94,129
12
188,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Grisha come to a contest and faced the following problem. You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q operations on the array. The i-th operation is described with three integers l_i, r_i and x_i (1 ≀ l_i ≀ r_i ≀ n, 1 ≀ x_i ≀ n) and means that you should add x_i to each of the elements with indices l_i, l_i + 1, …, r_i. After all operations you should find the maximum in the array. Grisha is clever, so he solved the problem quickly. However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?" Help Grisha, find all integers y between 1 and n such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to y. Input The first line contains two integers n and q (1 ≀ n, q ≀ 10^{4}) β€” the length of the array and the number of queries in the initial problem. The following q lines contain queries, one per line. The i-th of these lines contains three integers l_i, r_i and x_i (1 ≀ l_i ≀ r_i ≀ n, 1 ≀ x_i ≀ n), denoting a query of adding x_i to the segment from l_i-th to r_i-th elements of the array, inclusive. Output In the first line print the only integer k, denoting the number of integers from 1 to n, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations. In the next line print these k integers from 1 to n β€” the possible values of the maximum. Print these integers in increasing order. Examples Input 4 3 1 3 1 2 4 2 3 4 4 Output 4 1 2 3 4 Input 7 2 1 5 1 3 7 2 Output 3 1 2 3 Input 10 3 1 1 2 1 1 3 1 1 6 Output 6 2 3 5 6 8 9 Note Consider the first example. If you consider the subset only of the first query, the maximum is equal to 1. If you take only the second query, the maximum equals to 2. If you take the first two queries, the maximum becomes 3. If you take only the fourth query, the maximum becomes 4. If you take the fourth query and something more, the maximum becomes greater that n, so you shouldn't print it. In the second example you can take the first query to obtain 1. You can take only the second query to obtain 2. You can take all queries to obtain 3. In the third example you can obtain the following maximums: * You can achieve the maximim of 2 by using queries: (1). * You can achieve the maximim of 3 by using queries: (2). * You can achieve the maximim of 5 by using queries: (1, 2). * You can achieve the maximim of 6 by using queries: (3). * You can achieve the maximim of 8 by using queries: (1, 3). * You can achieve the maximim of 9 by using queries: (2, 3). Submitted Solution: ``` from itertools import permutations n, q = list(map(int, input().split())) s = [int(0) for i in range(n)] maxC = 0 maxValues = [] qList = [] for i in range(q): l, r, x = list(map(lambda x: int(x) - 1, input().split())) x += 1 qList.append((l, r, x)) lst = list(permutations(range(q)))[:(2**q // 3)] while lst: posl = lst.pop(0) sCopy = s.copy() for ind in posl: l, r, x = qList[int(ind)] for j in range(l, r + 1): sCopy[j] += x currentMax = max(sCopy) if currentMax not in maxValues and currentMax <= n: maxValues.append(currentMax) maxC += 1 print(maxC) print(*sorted(maxValues)) ```
instruction
0
94,130
12
188,260
No
output
1
94,130
12
188,261
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,639
12
189,278
Tags: brute force, greedy Correct Solution: ``` t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) else: s = 0 for i in range(n): s += abs(a[i] - b[i]) print(s // 2) for i in range(n): if a[i] < b[i]: while a[i] != b[i]: for j in range(i + 1, n): if a[i] == b[i]: break if a[j] >= 0 and a[j] > b[j]: print(j+1, i+1) a[j] -= 1 a[i] += 1 else: while a[i] != b[i]: for j in range(i + 1, n): if a[i] == b[i]: break if a[j] < b[j]: print(i+1, j+1) a[j] += 1 a[i] -= 1 ```
output
1
94,639
12
189,279
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,640
12
189,280
Tags: brute force, greedy Correct Solution: ``` for _ in range(int(input())): n=int(input()) arr1=list(map(int,input().split())) arr2=list(map(int,input().split())) pos=[] # f,g=0,0 # for i in range(n): # if arr1[i]<arr2[i]: # pos.append((i,arr2[i]-arr1[i])) # elif arr1[i]>arr2[i]: # neg.append((i,arr1[i]-arr2[i])) neg=[] if sum(arr1)!=sum(arr2): print(-1) else: for i in range(n): if arr2[i]-arr1[i]>0: for j in range(arr2[i]-arr1[i]): pos.append(i+1) elif arr2[i]-arr1[i]<0: for j in range(arr1[i]-arr2[i]): neg.append(i+1) print(len(pos)) for i in range(len(pos)): print(neg[i],pos[i]) ```
output
1
94,640
12
189,281
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,641
12
189,282
Tags: brute force, greedy Correct Solution: ``` def sex(a, b): if sum(a) != sum(b): print(-1) return if len(a) != len(b): print(-1) return result = '' plus = [] minus = [] for i in range(len(a)): if a[i] < b[i]: for _ in range(b[i] - a[i]): plus.append(i) else: for _ in range(a[i] - b[i]): minus.append(i) m = len(plus) print(m) for i in range(m): print(minus[i] + 1, plus[i] + 1) t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) sex(a, b) ```
output
1
94,641
12
189,283
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,642
12
189,284
Tags: brute force, greedy Correct Solution: ``` for idfghjk in range(int(input())): n=(int(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) ai=[] aj=[] for i in range(n): if a[i]>b[i]: for j in range(a[i]-b[i]): ai.append(i) if a[i]<b[i]: for j in range(b[i]-a[i]): aj.append(i) if len(ai)==len(aj): print(len(ai)) for i in range(len(ai)): print(ai[i]+1,aj[i]+1) else: print(-1) ```
output
1
94,642
12
189,285
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,643
12
189,286
Tags: brute force, greedy Correct Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ####################################### a=int(input()) for i in range(a): s=int(input()) z=list(map(int,input().split())) q=list(map(int,input().split())) large=[] small=[] for i in range(len(z)): if(z[i]>q[i]): large.append(i) elif(z[i]<q[i]): small.append(i) i=0 j=0 ans=[] flag=0 for i in range(len(small)): t=small[i] while(j<len(large) and z[t]!=q[t]): m=large[j] if(z[m]==q[m]): j+=1 continue; ans.append([m+1,t+1]) z[t]+=1 z[m]-=1 if(z[t]!=q[t]): flag=1 break; for i in range(len(z)): if(z[i]!=q[i]): flag=1 break; if(flag==1): print(-1) continue; print(len(ans)) for i in range(len(ans)): print(ans[i][0],ans[i][1]) ```
output
1
94,643
12
189,287
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,644
12
189,288
Tags: brute force, greedy Correct Solution: ``` t = int(input()) for i in range(t): l = int(input()) a = list( map(int,input().split()) ) b = list( map(int,input().split()) ) if a==b: print(0) continue r=[] rc = 0 for j in range(l): if a[j]>b[j]: for k in range(j+1,l): if a[k]<b[k]: tmp = min([abs(a[j]-b[j]),abs(a[k]-b[k])]) r.append([str(j+1)+" "+str(k+1),tmp]) a[j]-=tmp a[k]+=tmp rc+=tmp if a[j]==0: break elif a[j]<b[j]: for k in range(j+1,l): if a[k]>b[k]: tmp = min([abs(a[j]-b[j]),abs(a[k]-b[k])]) r.append([str(k+1)+" "+str(j+1),tmp]) a[j]+=tmp a[k]-=tmp rc+=tmp if a[j]==0: break if a!=b: print(-1) else: print(rc) for j in r: for k in range(j[1]): print(j[0]) ```
output
1
94,644
12
189,289
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,645
12
189,290
Tags: brute force, greedy Correct Solution: ``` import sys LI=lambda:list(map(int,sys.stdin.readline().split())) MI=lambda:map(int,sys.stdin.readline().split()) SI=lambda:sys.stdin.readline().strip('\n') II=lambda:int(sys.stdin.readline()) for _ in range(II()): n, a, b=II(), LI(), LI() v=[b[i]-a[i] for i in range(n)] if sum(v): print(-1) else: p, n=[], [] for i,x in enumerate(v): if x>0: for j in range(x):p.append(i+1) else: for j in range(-x):n.append(i+1) print(len(n)) while p or n: print(n.pop(), p.pop()) ```
output
1
94,645
12
189,291
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal.
instruction
0
94,646
12
189,292
Tags: brute force, greedy Correct Solution: ``` for _ in range(int(input())): n=int(input()) a = list(map(int,input().strip().split())) b = list(map(int,input().strip().split())) c=0 if len(a)==1: if a[0]==b[0]:print(0) else:print(-1) else: x=[] y=[] for i in range(n): if a[i]>b[i]: x+=[i+1]*(a[i]-b[i]) c+=(a[i]-b[i]) elif b[i]>a[i]: y+=[i+1]*(b[i]-a[i]) c+=(a[i]-b[i]) if c==0: print(len(x)) for j in range(len(x)): print(x[j],y[j]) else:print(-1) ```
output
1
94,646
12
189,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` R=lambda:map(int,input().split()) t,=R() while t: t-=1;R();a=[[],[]];s=i=0 for x,y in zip(R(),R()):i+=1;d=y-x;s+=d;a[d>0]+=[i]*abs(d) print(*s and[-1]or[len(a[0])]+[f'{i} {j}'for i,j in zip(*a)]) ```
instruction
0
94,647
12
189,294
Yes
output
1
94,647
12
189,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` def ans(a,b,n): if(sum(a)!=sum(b)): print(-1) return d = {} count = 0 for i in range(len(a)): #we count adds if(a[i]<b[i]): count+=(b[i]-a[i]) if(a[i]!=b[i]): d[i+1] = b[i]-a[i] print(count) d1 = {} d2 = {} for i in d: if d[i]<0: d2[i] = d[i] else: d1[i] = d[i] l1 = list(d1.keys())#add l2 = list(d2.keys())#subtract i = 0 j = 0 while(i<len(l1) and j<len(l2)): x = d1[l1[i]] y = d2[l2[j]] print(str(l2[j])+' '+str(l1[i])) d1[l1[i]]-=1 d2[l2[j]]+=1 if d1[l1[i]]==0: i+=1 if d2[l2[j]]==0: j+=1 return m = int(input()) for i in range(m): n = int(input()) arr = input().split() a = [] for i in arr: a.append(int(i)) arr = input().split() b = [] for i in arr: b.append(int(i)) ans(a,b,n) ```
instruction
0
94,648
12
189,296
Yes
output
1
94,648
12
189,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=[] d=[] if sum(a)!=sum(b): print(-1) continue for i in range(n): if a[i]>b[i]: for j in range(a[i]-b[i]): c.append(i+1) if a[i]<b[i]: for j in range(b[i]-a[i]): d.append(i+1) l=len(c) print(l) for i in range(l): print(c[i],d[i]) ```
instruction
0
94,649
12
189,298
Yes
output
1
94,649
12
189,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` from sys import stdin for _ in range(int(stdin.readline())): n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) b=list(map(int,stdin.readline().split())) ans=0 if sum(a)!=sum(b): print(-1) else: ans=0 arr=[] for i in range(n): j=i+1 while j<n and a[i]!=b[i]: if (a[i]>b[i] and a[j]>=b[j]) or (a[i]<b[i] and a[j]<=b[j]): j+=1 continue while a[j]!=b[j] and a[i]!=b[i]: if a[i]>b[i]: a[i]-=1 a[j]+=1 arr.append([i+1,j+1]) else: a[i]+=1 a[j]-=1 arr.append([j+1,i+1]) #print(i,j) #print(a) ans+=1 j+=1 print(ans) #print(a) for a in arr: print(*a) ```
instruction
0
94,650
12
189,300
Yes
output
1
94,650
12
189,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` n=int(input()) for _ in range(n): p=int(input()) d=[] a=list(map(int,input().split())) b=list(map(int,input().split())) if a==b: print(0) continue for i in range(len(a)): if a[i]==b[i]: d.append(i) j=0 w=0 i = len(a) - 1 po=[] while w==0: while i in d: i -= 1 while j in d: j += 1 a[i],a[j]=a[j],a[i] po.append([i+1,j+1]) if a[i]==b[i]: d.append(i) if a[j]==b[j]: d.append(j) if a==b: for k in po: print(k[0],k[-1]) break if i==j: print(-1) w=90 break ```
instruction
0
94,651
12
189,302
No
output
1
94,651
12
189,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if sum(a) != sum(b): print(-1) continue ac = a.copy() bc = b.copy() swaps = [] for i in range(n-1, -1, -1): #print(a, i) for j in range(i-1, -1, -1): if a[i] < b[i]: if a[j] >= 1: add = b[i]-a[i] if a[j] >= add: a[i] += add a[j] -= add for k in range(add): swaps.append([i+1,j+1]) else: tmp = a[j] a[i] += a[j] a[j] = 0 for k in range(tmp): swaps.append([i+1,j+1]) if a==b: print(len(swaps)) for swap in swaps: print(*sorted(swap)) continue swaps = [] for i in range(n-1, -1, -1): #print(bc, i) for j in range(i-1, -1, -1): if ac[i] > bc[i]: if bc[j] >= 1: add = ac[i]-bc[i] if bc[j] >= add: bc[i] += add bc[j] -= add for k in range(add): swaps.append([i+1,j+1]) else: tmp = bc[j] bc[i] += bc[j] bc[j] = 0 for k in range(tmp): swaps.append([i+1,j+1]) if ac==bc: print(len(swaps)) for swap in swaps: print(*sorted(swap)) continue else: print(-1) ```
instruction
0
94,652
12
189,304
No
output
1
94,652
12
189,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) li=[] if sum(a)==sum(b): li1=[] for i in range(n): li.append(a[i]-b[i]) for i in range(n): for j in range(i+1,n): if li[i]>0 and li[j]<0: y=min(li[i],abs(li[j])) li[i]-=y li[j]+=y for k in range(y): li1.append([i+1,j+1]) for j in range(i+1,n): if li[i]<0 and li[j]>0: y=min(abs(li[i]),li[j]) li[i]+=y li[j]-=y for k in range(y): li1.append([i+1,j+1]) print(len(li1)) for i in range(len(li1)): li1[i].sort() print(*li1[i]) else: print(-1) ```
instruction
0
94,653
12
189,306
No
output
1
94,653
12
189,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She chooses two indices i and j (1 ≀ i, j ≀ n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 ≀ i ≀ n. Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal. Please note, that you don't have to minimize the number of operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 100). The second line of each test case contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 100). The sum of all a_i does not exceed 100. The third line of each test case contains n integers b_1, b_2, ..., b_n (0 ≀ b_i ≀ 100). The sum of all b_i does not exceed 100. Output For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer m (0 ≀ m ≀ 100) in the first line β€” the number of operations. Then print m lines, each line consists of two integers i and j β€” the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with m ≀ 100. If there are multiple possible solutions, you can print any. Example Input 4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4 Output 2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5 Note In the first example, we do the following operations: * i = 2, j = 1: [1, 2, 3, 4] β†’ [2, 1, 3, 4]; * i = 3, j = 1: [2, 1, 3, 4] β†’ [3, 1, 2, 4]; In the second example, it's impossible to make two arrays equal. Submitted Solution: ``` t = int(input()) for _ in range(t): n = int(input()) a = [int(c) for c in input().split()] b = [int(d) for d in input().split()] x1 = sum(a) x2 = sum(b) if x1!=x2: print(-1) elif a==b: print(0) else: for i in range(n): for j in range(n): if a[i] > b[i] and a[j] < b[j]: while a[i]!=b[i] and a[j]!=b[j]: a[i]-=1 a[j]+=1 print(i+1, j+1) elif a[i] < b[i] and a[j] > b[j]: while a[j]>0 and a[i]!=b[i] and a[j]!=b[j]: a[i]+=1 a[j]-=1 print(j+1, i+1) ```
instruction
0
94,654
12
189,308
No
output
1
94,654
12
189,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it). You are given an array a consisting of n elements. You are allowed to replace any element with any integer number (and you may do so any number of times you need). What is the minimum number of replacements you have to perform in order to make the array almost increasing? Input The first line contains one integer n (2 ≀ n ≀ 200000) β€” the number of elements in a. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the array a. Output Print the minimum number of replaces you have to perform so that a is almost increasing. Examples Input 5 5 4 3 2 1 Output 3 Input 5 1 2 8 9 5 Output 0 Submitted Solution: ``` def inCreasingSeq(n,seq,startIndex): for i in range(startIndex,n-1): if(seq[i] > seq[i+1]): return i+1 return -1 def replace(index,seq): seq[index] = seq[index - 1] return def solve(n,seq): sortedList = list(sorted(seq)) if(sortedList == seq): print("0") return else: nbReplace = 0 ind = inCreasingSeq(n,seq,0) while ind != -1: replace(ind,seq) nbReplace+=1 ind = inCreasingSeq(n,seq,ind) print(nbReplace-1) nbT = int (input()) lis = list(map(int,input().split())) solve(nbT,lis) ```
instruction
0
95,007
12
190,014
No
output
1
95,007
12
190,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it). You are given an array a consisting of n elements. You are allowed to replace any element with any integer number (and you may do so any number of times you need). What is the minimum number of replacements you have to perform in order to make the array almost increasing? Input The first line contains one integer n (2 ≀ n ≀ 200000) β€” the number of elements in a. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the array a. Output Print the minimum number of replaces you have to perform so that a is almost increasing. Examples Input 5 5 4 3 2 1 Output 3 Input 5 1 2 8 9 5 Output 0 Submitted Solution: ``` def min_changes(li): change, check = 0, 0 li_len = len(li) if li_len in [0,1]: return change else: check = li[0] for i in range(1, len(li)): if check >= li[i]: li[i] = check +1 change += 1 check += 1 else: check = li[i] return change n = input() a = list(map(int,input().split())) print (min_changes(a)-1) ```
instruction
0
95,008
12
190,016
No
output
1
95,008
12
190,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it). You are given an array a consisting of n elements. You are allowed to replace any element with any integer number (and you may do so any number of times you need). What is the minimum number of replacements you have to perform in order to make the array almost increasing? Input The first line contains one integer n (2 ≀ n ≀ 200000) β€” the number of elements in a. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the array a. Output Print the minimum number of replaces you have to perform so that a is almost increasing. Examples Input 5 5 4 3 2 1 Output 3 Input 5 1 2 8 9 5 Output 0 Submitted Solution: ``` Number = int(input()) Numbers = input().split() count = 0 ; for i in range (0,Number-1) : if (int(Numbers[i]) > int(Numbers[i+1])) : count = count +1 print (count - 1) ```
instruction
0
95,009
12
190,018
No
output
1
95,009
12
190,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it). You are given an array a consisting of n elements. You are allowed to replace any element with any integer number (and you may do so any number of times you need). What is the minimum number of replacements you have to perform in order to make the array almost increasing? Input The first line contains one integer n (2 ≀ n ≀ 200000) β€” the number of elements in a. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the array a. Output Print the minimum number of replaces you have to perform so that a is almost increasing. Examples Input 5 5 4 3 2 1 Output 3 Input 5 1 2 8 9 5 Output 0 Submitted Solution: ``` def inCreasingSeq(n,seq,startIndex): for i in range(startIndex,n-1): if(seq[i] > seq[i+1]): return i+1 return -1 def replace(index,seq): seq[index] = seq[index - 1] return def solve(n,seq): nbReplace = 0 ind = inCreasingSeq(n,seq,0) while ind != -1: replace(ind,seq) nbReplace+=1 ind = inCreasingSeq(n,seq,ind) print(max(0,nbReplace-1)) nbT = int (input()) lis = list(map(int,input().split())) solve(nbT,lis) ```
instruction
0
95,010
12
190,020
No
output
1
95,010
12
190,021
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,272
12
190,544
"Correct Solution: ``` import sys import heapq n, q = map(int, input().split()) Q = [[] for _ in range(n)] ans = [] heapq.heapify(Q) for query in (line.split() for line in sys.stdin): t = int(query[1]) if query[0] == '0': u = int(query[2]) heapq.heappush(Q[t], -u) elif query[0] == '1' and Q[t]: ans.append(-Q[t][0]) elif query[0] == '2' and Q[t]: heapq.heappop(Q[t]) for i in ans: print(i) ```
output
1
95,272
12
190,545
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,273
12
190,546
"Correct Solution: ``` from heapq import heappush, heappop n, q = list(map(int, input().split(' '))) pqueues = [[] for i in range(n)] for i in range(q): op = list(map(int, input().split(' '))) if op[0] == 0: heappush(pqueues[op[1]], -op[2]) elif op[0] == 1: if len(pqueues[op[1]]) != 0: print(-1*pqueues[op[1]][0]) elif op[0] == 2: if len(pqueues[op[1]]) != 0: heappop(pqueues[op[1]]) ```
output
1
95,273
12
190,547
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,274
12
190,548
"Correct Solution: ``` class MaxHeapInt(object): def __init__(self, val): self.val = val def __lt__(self, other): return self.val > other.val def __eq__(self, other): return self.val == other.val def __str__(self): return str(self.val) def resolve(): import heapq n, Q = [int(i) for i in input().split()] ans = [[] for _ in range(n)] for _ in range(Q): q = [int(i) for i in input().split()] if q[0] == 0: heapq.heappush(ans[q[1]], MaxHeapInt(q[2])) elif q[0] == 1: if len(ans[q[1]]) > 0: print(ans[q[1]][0].val) else: if len(ans[q[1]]) > 0: heapq.heappop(ans[q[1]]) resolve() ```
output
1
95,274
12
190,549
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,275
12
190,550
"Correct Solution: ``` # AOJ ITP2_2_C: Priority Queue # Python3 2018.6.24 bal4u import heapq n, q = map(int, input().split()) Q = [[] for i in range(n)] for i in range(q): a = input().split() t = int(a[1]) if a[0] == '0': heapq.heappush(Q[t], -int(a[2])) # insert elif a[0] == '1' and Q[t]: print(-Q[t][0]) # getMax elif a[0] == '2' and Q[t]: heapq.heappop(Q[t]) # deleteMax ```
output
1
95,275
12
190,551
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,276
12
190,552
"Correct Solution: ``` import heapq n, q = [int(x) for x in input().split()] L = [ [] for _ in range(n)] for _ in range(q): c, t, x = [int(x) for x in (input()+ " 0").split()][:3] if c == 0: heapq.heappush(L[t],-x) elif c == 1: try: print(-L[t][0]) except IndexError: pass else: try: heapq.heappop(L[t]) except IndexError: pass ```
output
1
95,276
12
190,553
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,277
12
190,554
"Correct Solution: ``` # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_2_C&lang=jp # Priority Queue from collections import deque import sys input = sys.stdin.readline import heapq def loop_proc(): (n1,n2) = map(int,input().split()) wl =[] for i in range(n1): wl.append(list()) for i in range(n2): l = list(map(int,input().split())) if (l[0] == 0 ): n = l[1] d = l[2] heapq.heappush(wl[n],-1 * d) elif (l[0] == 1 ): if ( len(wl[l[1]]) != 0 ): tl = wl[l[1]] a = heapq.heappop(tl) heapq.heappush(tl,a) print (int(a) * -1 ) elif (l[0] == 2 ): if ( len(wl[l[1]]) != 0 ): tl = wl[l[1]] heapq.heappop(tl) if __name__ == '__main__': loop_proc() # import cProfile # pr = cProfile.Profile() # pr.runcall(loop_proc) # pr.print_stats() ```
output
1
95,277
12
190,555
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,278
12
190,556
"Correct Solution: ``` import heapq n, q = map(int, input().split()) stack = [[] for _ in range(n)] heapq.heapify(stack) for _ in range(q): query = list(map(int, input().split())) if query[0] == 0: heapq.heappush(stack[query[1]], -query[2]) elif query[0] == 1: if stack[query[1]] == []: pass else: print(-stack[query[1]][0]) elif query[0] == 2: if stack[query[1]] == []: pass else: heapq.heappop(stack[query[1]]) ```
output
1
95,278
12
190,557
Provide a correct Python 3 solution for this coding contest problem. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8
instruction
0
95,279
12
190,558
"Correct Solution: ``` import sys import heapq n, q = map(int, input().split()) queues = {str(i): [] for i in range(n)} lines = sys.stdin.readlines() for i in range(q): query, *arg = lines[i].split() if query == '0': # insert t x heapq.heappush(queues[arg[0]], -int(arg[1])) elif query == '1': # getMax if len(queues[arg[0]]): print(-queues[arg[0]][0]) elif query == '2': # deleteMax if len(queues[arg[0]]): heapq.heappop(queues[arg[0]]) else: raise AssertionError ```
output
1
95,279
12
190,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` import bisect n, q = map(int, input().split()) Q = [[] for i in range(n)] for i in range(q): query = list(map(int, input().split())) if query[0] == 0: bisect.insort_left(Q[query[1]], query[2]) elif query[0] == 1 and len(Q[query[1]]): print(Q[query[1]][-1]) elif query[0] == 2 and len(Q[query[1]]): Q[query[1]].pop(-1) ```
instruction
0
95,280
12
190,560
Yes
output
1
95,280
12
190,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` import heapq n,q = map(int,input().split()) Q = [[] for i in range(n)] for i in range(q): a = input().split() t = int(a[1]) if a[0] == "0":heapq.heappush(Q[t],-int(a[2])) elif a[0] == "1" and Q[t]: print(-Q[t][0]) elif a[0] == "2" and Q[t]: heapq.heappop(Q[t]) ```
instruction
0
95,281
12
190,562
Yes
output
1
95,281
12
190,563
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` import sys input = sys.stdin.readline import heapq N,Q = map(int,input().split()) H = [[] for _ in range(N)] for _ in range(Q): q = list(map(int,input().split())) if q[0] == 0: heapq.heappush(H[q[1]],-q[2]) elif q[0] == 1: if H[q[1]]: print(-H[q[1]][0]) else: if H[q[1]]: heapq.heappop(H[q[1]]) ```
instruction
0
95,282
12
190,564
Yes
output
1
95,282
12
190,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` import sys from collections import defaultdict from heapq import heappop, heappush n = int(sys.stdin.readline().split()[0]) A = defaultdict(list) ans = [] for query in sys.stdin: if query[0] == '0': t, x = query[2:].split() heappush(A[t], -int(x)) elif query[0] == '1': if A[query[2:-1]]: ans.append(f'{-A[query[2:-1]][0]}' + '\n') else: if A[query[2:-1]]: heappop(A[query[2:-1]]) sys.stdout.writelines(ans) ```
instruction
0
95,283
12
190,566
Yes
output
1
95,283
12
190,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` from heapq import heappush, heappop, heapify if __name__ == '__main__': n, q = input().split() n, q = int(n), int(q) S = [[] for i in range(n)] for i in range(q): query = input().split() if query[0] == '0': St = S[int(query[1])] #print(type(St), St, query[1]) heappush(St, int(query[2])) #print(St, heapify(St)) S[int(query[1])] = sorted(St) #print(S) else: if len(S[int(query[1])]) == 0: pass elif query[0] == '1': print(S[int(query[1])][-1]) else: S[int(query[1])].pop() ```
instruction
0
95,284
12
190,568
No
output
1
95,284
12
190,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Sun Jun 24 18:23:54 2018 ITP22C @author: maezawa """ n, q = list(map(int, input().split())) a = [[] for _ in range(n)] for i in range(q): c = list(map(int, input().split())) if c[0] == 0: if a[c[1]]: if a[c[1]][-1] < c[2]: a[c[1]].append(c[2]) else: for j in reversed(range(len(a[c[1]])-1)): if a[c[1]][j] < c[2]: a[c[1]].insert(j+1, c[2]) break else: a[c[1]].append(c[2]) elif c[0] == 1: if a[c[1]]: print(a[c[1]][-1]) else: if a[c[1]]: a[c[1]].pop() ```
instruction
0
95,285
12
190,570
No
output
1
95,285
12
190,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Sun Jun 24 18:23:54 2018 ITP22C @author: maezawa """ n, q = list(map(int, input().split())) a = [[] for _ in range(n)] for i in range(q): c = list(map(int, input().split())) if c[0] == 0: a[c[1]].append(c[2]) elif c[0] == 1: if a[c[1]]: print(max(a[c[1]])) else: if a[c[1]]: m = max(a[c[1]]) a[c[1]].remove(m) ```
instruction
0
95,286
12
190,572
No
output
1
95,286
12
190,573
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Priority queue is a container of elements which the element with the highest priority should be extracted first. For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations. * insert($t$, $x$): Insert $x$ to $Q_t$. * getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing. * deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty. Constraints * $1 \leq n \leq 1,000$ * $1 \leq q \leq 200,000$ * $-1,000,000,000 \leq x \leq 1,000,000,000$ Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively. Output For each getMax operation, print an integer in a line. Example Input 2 10 0 0 3 0 0 9 0 0 1 1 0 2 0 1 0 0 0 4 1 0 0 1 8 1 1 Output 9 3 4 8 Submitted Solution: ``` class binaryTree: def __init__(self, root = None): self.value = root self.left = None self.right = None def makeBntr(bnary, num): if bnary is None or bnary.value is None: return binaryTree(num) elif bnary.value is None: return binaryTree(num) elif bnary.value < num: bnary.left = makeBntr(bnary.left, num) else: bnary.right = makeBntr(bnary.right, num) return bnary def maxLeaf(bnary): if bnary.value is None: return 0 elif bnary.left is not None: return maxLeaf(bnary.left) else: return bnary def getLeaf(bnary): return maxLeaf(bnary).value def mkBntr(bnary, num): if bnary is None: return num elif bnary.value < num.value: bnary.left = mkBntr(bnary.left, num) else: bnary.right = mkBntr(bnary.right, num) return bnary def toLeft(bnary): if bnary.left is None: right = bnary.right bnary = None return bnary, right else: bnary.left, right = toLeft(bnary.left) return bnary, right def delLeaf(bnary): bnary, right = toLeft(bnary) if bnary is None: bnary = binaryTree() return bnary if right is None else mkBntr(bnary, right) if __name__ == '__main__': n, q = input().split() n, q = int(n), int(q) S = [binaryTree() for i in range(n)] count = 1 for i in range(q): query = input().split() if query[1] != "12": continue count += 1 bnary = S[int(query[1])] if query[0] == '0': S[int(query[1])] = makeBntr(bnary, int(query[2])) else: if bnary.value is None: pass elif query[0] == '1': print(getLeaf(bnary)) else: S[int(query[1])] = delLeaf(bnary) ```
instruction
0
95,287
12
190,574
No
output
1
95,287
12
190,575
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,351
12
190,702
Tags: dp, greedy, math Correct Solution: ``` import copy n,m,k=map(int,input().split()) A=list(map(int,input().split())) ANS=0 for i in range(m): B=copy.deepcopy(A) for j in range(i,n,m): B[j]-=k NOW=0 for j in range(i,n): if j%m==i: NOW=max(NOW+B[j],B[j]) else: NOW+=B[j] ANS=max(ANS,NOW) print(ANS) ```
output
1
95,351
12
190,703
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,352
12
190,704
Tags: dp, greedy, math Correct Solution: ``` '''input 5 3 10 1 2 10 2 3 ''' import math def max_sub(arr,n): dp = [0]*n dp[0] = arr[0] for i in range(1,n): dp[i] = max(dp[i-1]+arr[i],arr[i]) return max(0,max(dp)) n,m,k = map(int,input().split()) arr = list(map(int,input().split())) q = -math.inf dp = [0]*(300100) for i in range(300100): dp[i] = [q]*(11) if (m==1): for i in range(n): arr[i]= arr[i]-k print(max_sub(arr,n)) else: for i in range(n): dp[i][1] = arr[i]-k for j in range(m): if (i-1<0 or dp[i-1][j]==q): continue if ((j+1)%m!=1): dp[i][(j+1)%m] = dp[i-1][j]+arr[i] else: dp[i][(j+1)%m] = max(arr[i]-k,dp[i-1][j]+arr[i]-k) ma=0 for i in range(n): # s = "" for j in range(m): # s+=str(dp[i][j])+" " ma = max(ma,dp[i][j]) # print(s) print(ma) ```
output
1
95,352
12
190,705
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,353
12
190,706
Tags: dp, greedy, math Correct Solution: ``` from math import * n,m,k = map(int,input().split()) l = list(map(int,input().split())) a = [0 for i in range(n+1)] ans = 0 for M in range(m): min1 = 0 for i in range(1,n+1): a[i] = a[i-1] + l[i-1] if(i % m == M): a[i] -= k ans = max(ans,a[i]-min1) min1 = min(min1,a[i]) #print(a) print(ans) ```
output
1
95,353
12
190,707
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,354
12
190,708
Tags: dp, greedy, math Correct Solution: ``` n, m, k = map(int, input().split()) a = list(map(int, input().split())) best = 0 dp = [0] * (n + 1) for i in range(n): b2 = 0 for j in range(max(-1, i - m), i + 1): b2 = max(b2, dp[j] - k + sum(a[j + 1:i + 1])) dp[i] = max(b2, a[i] - k) best = max(best, dp[i]) print(best) # print(dp) ```
output
1
95,354
12
190,709
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,355
12
190,710
Tags: dp, greedy, math Correct Solution: ``` import sys n, m, k = list(map(int, sys.stdin.readline().strip().split())) a = list(map(int, sys.stdin.readline().strip().split())) b = [0] * (n+1) for i in range (1, n+1): b[i] = b[i-1] + m * a[i-1] - k M = [10 ** 20] * m ans = 0 for i in range (0, n+1): M[i % m] = min([M[i % m], b[i]]) for j in range (0, m): if i > j: ans = max([ans, b[i]-M[j]-k*((m*i+m-(i-j))%m)]) # print(j, M, ans) print(ans // m) ```
output
1
95,355
12
190,711
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,356
12
190,712
Tags: dp, greedy, math Correct Solution: ``` import os import sys from io import BytesIO, IOBase from collections import Counter import math as mt BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) mod = int(1e9) + 7 def power(k, n): if n == 0: return 1 if n % 2: return (power(k, n - 1) * k) % mod t = power(k, n // 2) return (t * t) % mod def totalPrimeFactors(n): count = 0 if (n % 2) == 0: count += 1 while (n % 2) == 0: n //= 2 i = 3 while i * i <= n: if (n % i) == 0: count += 1 while (n % i) == 0: n //= i i += 2 if n > 2: count += 1 return count # #MAXN = int(1e7 + 1) # # spf = [0 for i in range(MAXN)] # # # def sieve(): # spf[1] = 1 # for i in range(2, MAXN): # spf[i] = i # for i in range(4, MAXN, 2): # spf[i] = 2 # # for i in range(3, mt.ceil(mt.sqrt(MAXN))): # if (spf[i] == i): # for j in range(i * i, MAXN, i): # if (spf[j] == j): # spf[j] = i # # # def getFactorization(x): # ret = 0 # while (x != 1): # k = spf[x] # ret += 1 # # ret.add(spf[x]) # while x % k == 0: # x //= k # # return ret # Driver code # precalculating Smallest Prime Factor # sieve() def main(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) dp = [[0 for i in range(m)] for j in range(n)] ans = 0 for i in range(n): if m == 1: if i: dp[i][0] = max(a[i] - k, dp[i - 1][0] + a[i] - k) else: dp[i][0] = a[i] - k ans = max(ans, dp[i][0]) else: if i: for j in range(m): if (j <= i + 1 and j>=1) or (j==0 and i>=m-1): if j != 1: dp[i][j] = dp[i - 1][(j - 1 + m) % m] + a[i] else: dp[i][1] = max(a[i] - k, dp[i - 1][0] + a[i] - k) ans = max(ans, dp[i][j]) else: dp[i][1] = a[i] - k ans = max(ans, a[i] - k) #print(dp[i]) print(ans) # 7 1 10 # 2 -4 15 -3 4 8 3 # s=input() return if __name__ == "__main__": main() ```
output
1
95,356
12
190,713
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,357
12
190,714
Tags: dp, greedy, math Correct Solution: ``` import io, sys input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) n, m, k = mi() a = [None] + li() p = [0] * (n + 1) for i in range(1, n + 1): p[i] = p[i - 1] + a[i] s = [10 ** 16 for _ in range(m)] s[0] = k ans = 0 for i in range(1, n + 1): ans = max(ans, p[i] - min(s)) s[i % m] = min(s[i % m], p[i]) s[i % m] += k print(ans) ```
output
1
95,357
12
190,715
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
instruction
0
95,358
12
190,716
Tags: dp, greedy, math Correct Solution: ``` def naiveSolve(n,m,k,a): ans=0 L,R=-1,-1 for l in range(n): t=0 for r in range(l,n): t+=a[r] temp=t-k*(((r-l+1)+m-1)//m) if temp>ans: ans=temp L,R=l,r return ans,L,R return def main(): # n,m,k=10,5,5 # from random import randint # a=[randint(-5,5) for _ in range(n)] n,m,k=readIntArr() a=readIntArr() p=a.copy() for i in range(1,n): p[i]+=p[i-1] def rangeSum(l,r): if l==0: return p[r] else: return p[r]-p[l-1] dp=[0]*n # dp[i] is the max value ending at a[i] for i in range(n): if i-m>=0: dp[i]=max(dp[i],dp[i-m]+rangeSum(i-m+1,i)-k) # join to prev block # don't join to prev block for j in range(max(0,i-m+1),i+1): dp[i]=max(dp[i],rangeSum(j,i)-k) ans=max(dp) print(ans) # ans2,L,R=naiveSolve(n,m,k,a) ## # if ans!=ans2: # print('a:{} ans:{} ans2:{} L:{} R:{}'.format(a,ans,ans2,L,R)) # print(dp) return import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) # input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] # def readFloatArr(): # return [float(x) for x in input().split()] def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m]) dv=defaultValFactory;da=dimensionArr if len(da)==1:return [dv() for _ in range(da[0])] else:return [makeArr(dv,da[1:]) for _ in range(da[0])] def queryInteractive(l,r): print('? {} {}'.format(l,r)) sys.stdout.flush() return int(input()) def answerInteractive(x): print('! {}'.format(x)) sys.stdout.flush() inf=float('inf') MOD=10**9+7 # MOD=998244353 from math import gcd,floor,ceil for _abc in range(1): main() ```
output
1
95,358
12
190,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` if __name__ == '__main__': n, m, k = map(int, input().split()) aa = list(map(int,input().split())) ans = 0 for start in range(m): ac = aa[:] for i in range(start, n, m): ac[i] -= k cur = 0 for i in range(start, n): if i%m == start: cur = max(ac[i] + cur, ac[i]) else: cur += ac[i] ans = max(cur, ans) print(ans) ```
instruction
0
95,359
12
190,718
Yes
output
1
95,359
12
190,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` n, m, k = [int(i) for i in input().split()] A = [int(i) for i in input().split()] bestbest = 0 def brute(n, m, k, A): ans = 0 val = (0, 0) for i in range(n): for j in range(i, n): if ans < sum(A[i:j+1]) - k*(ceil((j-i+1)/m)): ans = sum(A[i:j+1]) - k*(ceil((j-i+1)/m)) val = (i, j) return val, ans for off in range(m): B = A[off:] C = [] canstart = [] for i in range(len(B)): if i%m == 0: C.append(-k) canstart.append(1) canstart.append(0) C.append(B[i]) best = 0 run = 0 for i in range(len(C)): run += C[i] if run < -k: run = -k best = max(best, run) #print(best, C) bestbest = max(bestbest, best) print(bestbest) ```
instruction
0
95,360
12
190,720
Yes
output
1
95,360
12
190,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` from sys import stdin, stdout, exit n, m, k = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) def bf(a): best = 0 best_arg = (-1, -1) for i in range(n): for j in range(i, n): cur = sum(a[i:j+1]) - k*((j - i) // m + 1) if cur > best: best = max(best, cur) best_arg = (i,j) return best, best_arg def max_sum(a): if len(a) == 0: return 0 elif len(a) == 1: return max(0, a[0] - k) mid = len(a) // 2 l_rec = max_sum(a[:mid]) r_rec = max_sum(a[mid:]) l_bests = [0]*m r_bests = [0]*m l_sum = 0 for idx in range(1,mid+1): l_sum += a[mid-idx] if idx % m == 0: l_sum -= k l_bests[idx%m] = max(l_bests[idx%m], l_sum) r_sum = 0 for idx in range(0, len(a)-mid): r_sum += a[idx+mid] if (idx+1) % m == 0: r_sum -= k r_bests[(idx+1)%m] = max(r_bests[(idx+1)%m], r_sum) # print("Array:", a, "mid:", mid) # print(l_bests) # print(r_bests) best_acr = 0 for i in range(m): for j in range(m): best_acr = max(best_acr, l_bests[i] + r_bests[j] - (k if i+j>0 else 0) - (k if i+j>m else 0)) ans = max(l_rec,r_rec, best_acr) # print("Answer:", ans) return ans ans = max_sum(a) stdout.write(str(ans) + "\n") #stdout.write(str(bf(a))+"\n") ```
instruction
0
95,361
12
190,722
Yes
output
1
95,361
12
190,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` import sys import math as mt import bisect input=sys.stdin.readline #t=int(input()) t=1 def ncr_util(): inv[0]=inv[1]=1 fact[0]=fact[1]=1 for i in range(2,300001): inv[i]=(inv[i%p]*(p-p//i))%p for i in range(1,300001): inv[i]=(inv[i-1]*inv[i])%p fact[i]=(fact[i-1]*i)%p def solve(): pre=0 dp=[0]*(n+1) ans=0 for i in range(n): ss,maxi=0,0 if i<m: pre+=l[i] else: pre+=l[i] pre-=l[i-m] for j in range(i,max(i-m,-1),-1): ss+=l[j] maxi=max(maxi,ss-k) if i>=m: dp[i]=max(dp[i-m]+pre-k,maxi) else: dp[i]=max(dp[i],maxi) ans=max(dp[i],ans) return ans for _ in range(t): #n=int(input()) #n1=int(input()) #s=input() #n=int(input()) n,m,k=(map(int,input().split())) #n1=n #a=int(input()) #b=int(input()) #a,b,c,r=map(int,input().split()) #x2,y2=map(int,input().split()) #n=int(input()) #s=input() #s1=input() #p=input() l=list(map(int,input().split())) pref=[0]*(n+1) for i in range(n): pref[i+1]=pref[i]+l[i] #l=str(n) #l.sort(reverse=True) #l2.sort(reverse=True) #l1.sort(reverse=True) print(solve()) ```
instruction
0
95,362
12
190,724
Yes
output
1
95,362
12
190,725