description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) min1 = [0] * (n + 1) max1 = [0] * (n + 1) l = list(map(int, input().split())) for i in l: if i > 0: min1[i - 1] += 1 if i != 0: max1[0] += n - i + 1 max1[i] -= n - i + 1 if i < n: max1[i + 1] += n - i else: max1[1] += n - i for i in range(n - 1, -1, -1): min1[i] += min1[i + 1] for i in range(1, n): max1[i] += max1[i - 1] for i in range(n): print(min1[i], max1[i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
T = int(input()) for tr in range(T): N = int(input()) A = list(map(int, input().split(" "))) BCount = [0] * (N + 1) Bmin = [-1] * N Bmax = [-1] * N for i in range(N): BCount[A[i]] += 1 Nmin = N Nmax = 0 for i in range(N): Nmin -= BCount[i] Nmax += BCount[i] * (N - i) Bmin[i] = Nmin for i in range(N): Bmax[i] = Nmax - BCount[i] * (N - i) + Bmin[i] for i in range(N): print(Bmin[i], Bmax[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for t in range(int(input())): n = int(input()) minn = [0] * (n + 1) maxl = [0] * (n + 1) maxr = [0] * (n + 1) x1 = map(int, input().split()) for x in x1: minn[0] += 1 minn[x] -= 1 maxl[0] += n - x + 1 maxl[x] -= n - x + 1 maxr[n - 1] += n - x maxr[x] -= n - x for i in range(1, n + 1): minn[i] += minn[i - 1] maxl[i] += maxl[i - 1] for i in range(n - 1, -1, -1): maxr[i] += maxr[i + 1] for i in range(0, n): temp = maxl[i] + maxr[i] print(minn[i], temp)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
def update(d, l, r, x): d[l] += x d[r + 1] -= x for i in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] mn = [(0) for i in range(n + 1)] mx = [(0) for i in range(n + 1)] for i in a: if i != 0: update(mn, 0, i - 1, 1) update(mx, 0, i - 1, n - (i - 1)) if i != n: update(mx, i + 1, n - 1, n - i) for i in range(1, n + 1): mx[i] += mx[i - 1] mn[i] += mn[i - 1] for i in range(n): print(mn[i], end=" ") print(mx[i])
FUNC_DEF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) li = list(map(int, input().split())) presum = [0] * n maxl = [0] * n maxr = [0] * n for i in range(n): maxl[0] += n - li[i] + 1 maxr[-1] += n - li[i] if li[i] < n: presum[li[i]] -= 1 maxl[li[i]] -= n - li[i] + 1 maxr[li[i]] -= n - li[i] presum[0] += n for i in range(1, n): presum[i] += presum[i - 1] maxl[i] += maxl[i - 1] for i in range(n - 2, -1, -1): maxr[i] += maxr[i + 1] for i in range(n): x = maxl[i] + maxr[i] print(presum[i], x)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
import sys input = lambda: sys.stdin.readline() T = int(input()) for _ in range(T): n = int(input().strip()) a = list(map(int, input().strip().split())) a.sort() a2 = [] dic = {} for i in a: if i not in dic.keys(): dic[i] = 1 if a2 != n: a2.append(i) else: dic[i] += 1 L = [n for i in range(n)] j = 0 if a[j] == 0: L[0] -= dic[0] j += 1 for i in range(1, n): if j == len(a2): L[i] = L[i - 1] continue if i != a2[j]: L[i] = L[i - 1] else: L[i] = L[i - 1] - dic[a2[j]] j += 1 y = n * n - sum(a) M = [y for i in range(n)] for i in range(n): if a[i] != n: M[a[i]] -= n - a[i] for i in range(n): x = L[i] y = M[i] + x print(x, y)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for a in range(t): n = int(input()) l = list(map(int, input().split())) s = [0] * n p = [n**2 - sum(l)] * n for i in range(n): if l[i] < n: s[l[i]] += 1 p[l[i]] -= n - l[i] for i in range(n): max = p[i] min = s[i] if i < n - 1: s[i + 1] += s[i] max += n - min print(n - min, max)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for ti in range(t): n = int(input()) mex = list(map(int, input().split())) mexcount = [0] * (n + 1) for m in mex: mexcount[m] = mexcount[m] + 1 mexsum = [0] * (n + 1) mexcountsum = [0] * (n + 1) mexsum[0] = 0 mexcountsum[0] = mexcount[0] for i in range(1, n + 1): mexsum[i] = mexsum[i - 1] + mexcount[i] * i mexcountsum[i] = mexcountsum[i - 1] + mexcount[i] for i in range(n): min_ = mexcountsum[n] - mexcountsum[i] max_ = (1 + n) * min_ - mexsum[n] + mexsum[i] if i != 0: max_ = max_ + n * mexcountsum[i - 1] - mexsum[i - 1] print(min_, max_)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) while t > 0: t -= 1 n = int(input()) a = [int(x) for x in input().split()] h = [(0) for x in range(n + 1)] d = [(0) for x in range(n + 1)] post = [(0) for x in range(n + 1)] h[0] = n for i in range(n): x = a[i] h[x] -= 1 d[x] = d[x] - n + x - 1 post[x] = post[x] - n + x d[0] += n - x + 1 post[n - 1] += n - x for i in range(1, n + 1): d[i] += d[i - 1] for i in range(1, 1 + n): h[i] += h[i - 1] for i in range(n - 1, -1, -1): post[i] += post[i + 1] for i in range(n): x = h[i] m1, m2 = 0, 0 print(h[i], d[i] + post[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
def main(): n = int(input()) arr = list(map(int, input().split())) mn = [0] * (n + 1) mx = [0] * (n + 1) mxr = [0] * (n + 1) for i in range(n): a = arr[i] mn[0] += 1 mn[a] -= 1 mx[0] += n - a + 1 mx[a] -= n - a + 1 mxr[n - 1] += n - a mxr[a] -= n - a for i in range(1, n + 1): mn[i] += mn[i - 1] mx[i] += mx[i - 1] i = n - 1 while i >= 0: mxr[i] += mxr[i + 1] i -= 1 for i in range(n): print(mn[i], mx[i] + mxr[i]) return for _ in range(int(input())): main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
T = int(input()) for _ in range(T): N = int(input()) maxrarr = [(0) for i in range(N + 1)] flag = 0 call = 1 bool = True arr = list(map(int, input().split())) maxlarr = [(0) for i in range(N + 1)] minarr = [(0) for i in range(N + 1)] for i in range(N): minarr[0] += 1 minarr[arr[i]] -= 1 call += 2 maxlarr[0] += N - arr[i] + 1 maxlarr[arr[i]] -= N - arr[i] + 1 flag = 2 bool = False maxrarr[N - 1] += N - arr[i] maxrarr[arr[i]] -= N - arr[i] for i in range(1, N + 1): minarr[i] += minarr[i - 1] call = 0 maxlarr[i] += maxlarr[i - 1] for i in range(N - 1, -1, -1): maxrarr[i] += maxrarr[i + 1] bool = True call = 6 flag += 1 ans = "" for i in range(N): ans = maxlarr[i] + maxrarr[i] print(str(minarr[i]) + " " + str(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for h in range(int(input())): n = int(input()) x = list(map(int, input().split())) sure = [0] * n r = [0] * n l = [0] * n for i in x: if i + 1 < n: r[i + 1] += n - i if i - 1 >= 0: l[i - 1] += n - i if i - 1 >= 0: sure[i - 1] += 1 for i in range(len(sure) - 2, -1, -1): sure[i] += sure[i + 1] l[i] += l[i + 1] for i in range(1, len(r)): r[i] += r[i - 1] for i in range(n): print(sure[i], sure[i] + r[i] + l[i], end=" ") print("")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) a.sort() sumVal = sum(a) j = 0 for i in range(n): while j < n and a[j] < i: j += 1 k = j if j < n and i == a[j]: while k < n and a[k] == i: k += 1 k -= 1 if j < n and i == a[j]: print( n - k - 1, n * (n - (k - j + 1)) - (sumVal - i * (k - j + 1)) + n - k - 1, ) else: print(n - j, n * n - sumVal + n - j)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) arr = sorted(list(map(int, input().split()))) freq = [(0) for i in range(n + 1)] atleast = [(0) for i in range(n)] extra = sum([(n - e) for e in arr]) for e in arr: freq[e] += 1 tmp = 0 for i in range(n, 0, -1): tmp += freq[i] atleast[i - 1] = tmp for i in range(n): print(atleast[i], atleast[i] + extra - freq[i] * (n - i))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) least = (n + 1) * [0] most = (n + 69) * [0] for x in arr: least[0] += 1 most[0] += n - x + 1 least[x] -= 1 most[x] -= n - x + 1 most[x + 1] += n - x for i in range(n): if i: least[i] += least[i - 1] most[i] += most[i - 1] print(least[i], most[i])
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER FOR VAR VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) l = list(map(int, input().split())) l.sort() smalls = [(l[i] - i) for i in range(n)] tols = [(l[i] - i + p - 1) for i in range(p - 1, n)] smol = max(smalls) tol = min(tols) out = list(range(smol, tol)) print(len(out)) print(" ".join(map(str, out)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 0 ansls = [] mx = max(a) for i in range(1, mx + 1): anstmp = 1 for j in range(n)[::-1]: if a[j] - j > i: anstmp = 0 else: anstmp *= n - max(i, a[j]) + i - (n - j - 1) anstmp %= p if anstmp: ans += 1 ansls.append(i) print(ans) print(*ansls)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def read_list(): return list(map(int, input().strip().split(" "))) def print_list(l): print(" ".join(map(str, l))) n, p = read_list() a = read_list() a.sort() mi = max(a[i] - i for i in range(n)) res = [] ll = [] x = mi now = x i = 0 dic = [[-1]] for step in range(n): while i < n and now >= a[i]: i += 1 now += 1 tmp = (i - step) % p tmp = (p - tmp) % p if step >= tmp: dic.append([tmp, step]) dic.pop(0) for i in range(len(dic) - 1, 0, -1): if dic[i][0] <= dic[i - 1][1] - 1: dic[i - 1][1] = dic[i][1] dic[i - 1][0] = min(dic[i][0], dic[i - 1][0]) dic.pop(i) las = 0 for d in dic: flag = True for i in range(las, d[0]): if i >= p - 1: flag = False break res.append(mi + i) las = d[1] + 1 if not flag: break if dic: for i in range(dic[-1][-1] + 1, p - 1): res.append(mi + i) print(len(res)) print_list(res)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = list(map(int, input().split())) a = list(map(int, input().split())) num = [0] * 5001 for i in a: num[i] += 1 for i in range(5000): num[i + 1] += num[i] ans = [] for x in range(1, 2001): temp = 1 candy = x for i in range(x, x + n): temp *= num[candy] - (i - x) temp %= p candy += 1 if temp % p != 0: ans.append(x) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
from sys import stdin, stdout def main(): n, p = map(int, stdin.readline().split()) ary = list(map(int, stdin.readline().split())) mxm = max(ary) mnm = min(ary) offset = max(mnm, mxm - n) m = 2 * n cf = [0] * m xs = [1] * m ibi = [0] * m for elem in ary: idx = max(0, elem - offset) cf[idx] = cf[idx] + 1 cf[0] = cf[0] % p for idx in range(1, m): cf[idx] = (cf[idx] + cf[idx - 1]) % p for idx in range(m): ibi[idx] = (idx + offset) % p + p - cf[idx] ibi[idx] = ibi[idx] % p modp = [0] * p for idx in range(n): modp[ibi[idx]] += 1 for idx in range(n, m): x = (idx - n + offset) % p if modp[x] > 0: xs[idx - n] = 0 modp[ibi[idx - n]] -= 1 modp[ibi[idx]] += 1 result = [] for idx in range(n): if xs[idx] == 1: result.append(str(idx + offset)) stdout.write(str(len(result))) stdout.write("\n") stdout.write(" ".join(result)) return main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() mx = -float("inf") for i in range(n): if a[i] - i > mx: mx = a[i] - i imx = i flag = True nmx = -float("inf") for i in range(p - 1, n): if mx + i - (p - 1) >= a[i]: flag = False break nmx = max(nmx, mx + i - p - a[i] + 1) if flag: print(-nmx) for i in range(0, -nmx): print(mx + i, end=" ") print() else: print(0)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = list(map(int, input().split(" "))) a = list(map(int, input().split(" "))) a.sort() result = [] _min = 0 for i in range(len(a) - 1, -1, -1): if _min <= a[i] - i: _min = a[i] - i _max = a[-1] for i in range(len(a) - 1, p - 2, -1): if _max >= p - 2 - i + a[i]: _max = p - 2 - i + a[i] result = max(_max - _min + 1, 0) print(result) if result > 0: for i in range(_min, _max + 1): print(i, end=" ")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) m = max(a) x = m - n + 1 lis = [] for i in range(x, m): l = [] for e in a: w = e - i if w <= 0: l.append(n) else: l.append(n - w) l.sort() am = True for j in range(n): if (l[j] - j) % p == 0: am = False break if am: lis.append(i) print(len(lis)) print(*lis)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) def calc(x): global n, p, a o = [0] * (n + 1) for i in a: o[max(0, min(n, i - x))] += 1 s = 0 ans = 1 for i in range(n): s += o[i] if s <= 0: return 0 ans = ans * s % p s -= 1 return ans ans = [] for x in range(4020): if calc(x): ans.append(x) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def ican(a, x): k = x wr = 0 for i in range(len(a)): if a[i] <= k: wr += 1 else: wr -= a[i] - k k = a[i] if wr < 0: return False wr += 1 return True def bnpleft(a): r = max(a) l = -1 while r - l > 1: h = (r + l) // 2 if ican(a, h): r = h else: l = h return l def fa(a, x, p): k = x wr = 0 for i in range(len(a)): if a[i] <= k: wr += 1 else: nk = wr // p * p wr -= a[i] - k if wr < nk: return False k = a[i] if wr < 0: return False wr += 1 if wr >= p: return False else: return True def bnpr(a, p, left): l = left r = max(a) while r - l > 1: h = (r + l) // 2 if fa(a, h, p): l = h else: r = h return l def solve(): n, p = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() ll = bnpleft(lst) rr = bnpr(lst, p, ll) print(rr - ll) for i in range(ll + 1, rr + 1): print(i, end=" ") for i in range(1): solve()
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = sys.stdin.readline n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = [] for x in range(min(a), max(a) + 1): stack = 0 j = -1 turn = 0 pre_j = -1 flag = True flag2 = True while j < n: while j + 1 < n and x + turn >= a[j + 1]: j += 1 stack += j - pre_j if stack <= 0: flag = False break if stack >= p: flag2 = False stack -= 1 turn += 1 if turn == n: break pre_j = j if flag and flag2: ans.append(x) print(len(ans)) print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def places(num, v): if num >= v + n: return 0 if num < v: return n return n - (num - v) def check(num): for i in range(n - 1, -1, -1): count = max(0, places(b[i], num) - (n - 1 - i)) if count % p == 0: return True return False n, p = map(int, input().split()) a = list(map(int, input().split())) b = sorted(a) minn = b[0] maxx = b[-1] ans = [] for i in range(minn, maxx): if not check(i): ans.append(i) print(len(ans)) print(*ans)
FUNC_DEF IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR RETURN BIN_OP VAR BIN_OP VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
lis = input().split() n, p = int(lis[0]), int(lis[1]) lis = input().split() a = [0] * n for i in range(n): a[i] = int(lis[i]) a.sort() xminn = a[0] for i in range(1, n): xminn = max(a[i] - i, xminn) for i in range(n): a[i] = min(xminn - a[i] + 1 + i, i + 1) lenn = n i = p while i <= n: lenn = min(i - a[i - 1], lenn) i += p if lenn == 0: print(0) else: notAllowed = [False] * lenn for i in range(n): uplim = min(a[i] + lenn - 1, i + 1) val = ((a[i] - 1) // p + 1) * p if val <= uplim: notAllowed[val - a[i]] = True good = [] for i in range(lenn): if not notAllowed[i]: good.append(xminn + i) print(len(good)) for i in good: print(i, end=" ") print()
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def asterism(p, a): n, m, M = len(a), 1, max(a) - 1 for i in range(n): m = max(m, a[i] - i) for i in range(n - p + 1): M = min(M, a[p + i - 1] - i - 1) print(max(0, M - m + 1)) for i in range(m, M + 1): print(i, end=" ") asterism(int(input().split()[1]), sorted([int(i) for i in input().split()]))
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys def input(): return sys.stdin.readline().rstrip() def input_split(): return [int(i) for i in input().split()] n, p = input_split() arr = input_split() maxi = max(arr) count = 0 is_div = [(1) for i in range(maxi + 1)] freqs = [(0) for i in range(4002)] for a in arr: freqs[a] += 1 for i in range(1, 4002): freqs[i] += freqs[i - 1] touched = [(False) for i in range(4002)] for i in range(4002): shift = freqs[i] % p while shift < n: potential = i - shift shift += p if potential >= 0 and potential <= maxi: is_div[potential] = 0 if potential < 0: break if touched[potential]: break else: touched[potential] = True ans = sum(is_div[: maxi + 1]) print(ans) xs = [x for x in range(maxi + 1) if is_div[x] == 1] print(*xs, sep=" ")
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys def LI(): return [int(x) for x in sys.stdin.readline().split()] def solve(): n, p = LI() a = LI() a.sort() ap = [i for i in a[p - 1 :]] ap = [(ap[i] - i) for i in range(len(ap))] M = min(ap) b = [(a[i] - i) for i in range(n)] m = max(b) ans = list(range(m, M)) print(len(ans)) print(*ans) return solve()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def solve(n, p, array): array.sort() array1 = [(i + 1 - array[i]) for i in range(n)] m = min(array1) min_x = 1 - min(m, 0) valid = [(1) for i in range(n)] max_v = n - 1 for i in range(n): a = array1[i] + min_x if (i + 1) % p == 0: max_v = min(array[i] - min_x - 1, max_v) if a <= i + 1: cur = -a % p end = min(i + 1 - a, max_v) while cur <= end: valid[cur] = 0 cur += p res = [] for i in range(max_v + 1): if valid[i]: res.append(min_x + i) print(len(res)) print(*res) n, p = [int(s) for s in input().split()] array = [int(s) for s in input().split()] solve(n, p, array)
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
from sys import stdin n, p = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) a.sort() x = 0 aa = [] j = 0 for i in range(n): if x + i < a[i]: x = a[i] - i if a[i] != a[j]: aa.append((a[j], i - j)) j = i else: aa.append((a[j], n - j)) C = 2000 c, d = 0, 0 for i in range(len(aa)): if aa[i][0] <= x: c += aa[i][1] else: _d = aa[i][0] - x itv = _d - d d = _d c = c + aa[i][1] - itv if d + c >= p: C = min(C, p - 1 - c) if c >= p: C = -1 break print(C + 1) print(" ".join([str(ans) for ans in range(x, x + C + 1)]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def solution(n, a, p): result = [] r = [] a.sort() for i in range(n): r.append(-a[i] + i + 1) remainder = [] for i in range(p): remainder.append(0) for i in range(p - 1, n): n_a_re = (p - r[i]) % p remainder[n_a_re] += 1 min_x = 1 - n + a[n - 1] for i in range(2, n + 1): if i - n + a[n - i] > min_x: min_x = i - n + a[n - i] result += get_x(min_x, a[p - 1], remainder, p, n, p - 2) return result def get_x(start, end, remainder, p, n, id): v1 = start // p r1 = start % p v2 = end // p r2 = end % p arr = [] s_id = -1 e_id = -1 if end > start: for i in range(len(remainder)): if remainder[i] == 0: arr.append(v1 * p + i) if i >= r1 and s_id == -1: s_id = len(arr) - 1 if i >= r2 and e_id == -1: e_id = len(arr) - 1 period = len(arr) for _ in range((v2 - v1) * period): arr.append(arr[-period] + p) if s_id == -1: s_id = period if e_id == -1: e_id = period remainder[(p + end - id - 2) % p] -= 1 return arr[s_id : len(arr) - period + e_id] else: remainder[(p + end - id - 2) % p] -= 1 return [] num = input() num = num.split(" ") n = int(num[0]) p = int(num[1]) a = list(map(int, input().split(" "))) result = solution(n, a, p) print(len(result)) print(" ".join(list(map(str, result))))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, k = list(map(int, input().strip().split())) list1 = list(map(int, input().strip().split())) list1.sort() maxima = list1[n - 1] m = dict() curr = 1 count = 0 for i in range(n): if list1[i] != curr: for j in range(curr, list1[i]): m[j] = count curr = list1[i] count += 1 for j in range(curr, maxima + 1): m[j] = count for j in range(maxima, 0, -1): if j == maxima: continue m[j] = max(m[j], m[j + 1] - 1) for i in range(n - 1, 0 - 1, -1): if i == n - 1: temp = list1[n - 1] else: temp = max(list1[i], temp - 1) start = temp ans = [] while 1: if m[start] < k: ans.append(start) else: break start += 1 print(len(ans)) for val in ans: print(val, end=" ") print()
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = sys.stdin.readline def judge1(x): c = 0 ri = 0 now = x for _ in range(n): while ri < n: if a[ri] <= now: c += 1 ri += 1 else: break if c == 0: return False c -= 1 now += 1 return True def judge2(x): c = 0 ri = 0 now = x for _ in range(n): while ri < n: if a[ri] <= now: c += 1 ri += 1 else: break if c >= p: return False c -= 1 now += 1 return True n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() l, r = 0, 10**9 while l <= r: m = (l + r) // 2 if judge1(m): r = m - 1 else: l = m + 1 s = l l, r = 0, 10**9 while l <= r: m = (l + r) // 2 if judge2(m): l = m + 1 else: r = m - 1 t = r if s > t: print(0) exit() print(t - s + 1) print(*[i for i in range(s, t + 1)])
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def binary(arr, x, n, p): less = 0 for i in range(n): while less < n and x + i >= arr[less]: less += 1 C = less - i if C <= 0: return -1 if C >= p: return 1 return 0 def help(): n, p = map(int, input().split(" ")) arr = list(map(int, input().split(" "))) arr.sort() start = 0 end = 1000000001 mini = 1000000001 while start <= end: mid = (start + end) // 2 temp = binary(arr, mid, n, p) if temp == 0: mini = min(mid, mini) if temp >= 0: end = mid - 1 else: start = mid + 1 start = 0 end = 1000000001 maxi = 0 while start <= end: mid = (start + end) // 2 temp = binary(arr, mid, n, p) if temp == 0: maxi = max(mid, maxi) if temp > 0: end = mid - 1 else: start = mid + 1 if maxi < mini: print(0) print() return print(maxi - mini + 1) for i in range(mini, maxi + 1): print(i, end=" ") print() for _ in range(1): help()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def solve(n, p, x, a): res_ptn = 1 r = 0 for l in range(n): while r < n and a[r] <= x + l: r += 1 res_ptn *= r - l res_ptn %= p return res_ptn != 0 n, p = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) ans = [] for x in range(1, 2000 + 2): if solve(n, p, x, a): ans.append(x) print(len(ans)) print(*ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() cur_pass = 0 for i in range(n): cur_pass = max(a[i] - i, cur_pass) min_pass = cur_pass ans = [] done = True l = cur_pass r = a[-1] while l <= r: mid = (l + r) // 2 cur_pass = mid i = 0 while i < n and a[i] <= cur_pass: i += 1 candies = cur_pass options = i while options: if options >= p: r = mid - 1 break candies += 1 options -= 1 while i < n and a[i] <= candies: i += 1 options += 1 if r == mid - 1: pass else: l = mid + 1 for i in range(min_pass, r + 1): ans += [str(i)] print(len(ans)) print(" ".join(ans))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR LIST FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = list(map(int, input().split(" "))) a = list(map(int, input().split(" "))) a.sort() result = [] for x in range(a[-1]): fail = 0 for i in range(len(a) - 1, -1, -1): if x + i < a[i]: fail = 1 break elif p <= min(i + 1, i - (a[i] - x - 1)): fail = 1 break if fail == 0: result.append(str(x)) print(len(result)) if result: print(" ".join(result))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) for i in range(2000, 0, -1): a += [i] xarr = [0] * 2001 for i in range(n): xarr[a[i]] += 1 for i in range(1, 2001): xarr[i] += xarr[i - 1] count = 0 good = [] for x in range(1, max(a) + 1): counts = 0 for i in range(x, x + n): if (xarr[min(i, 2000)] - counts) % p == 0: break counts += 1 else: count += 1 good += [x] print(count) for i in range(len(good)): print(good[i], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR LIST VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def places(num, v): if num >= v + n: return 0 if num < v: return n return n - (num - v) def check(num): for i in range(n - 1, -1, -1): count = max(0, places(b[i], num) - (n - 1 - i)) if count == 0: return True if count % p == 0: return False return False def check2(num): for i in range(n - 1, -1, -1): count = max(0, places(b[i], num) - (n - 1 - i)) if count % p == 0: return True return False n, p = map(int, input().split()) a = list(map(int, input().split())) b = sorted(a) minn = b[0] maxx = b[-1] low = 0 high = maxx - 1 while low < high: mid = (low + high) // 2 if check(mid): low = mid + 1 else: high = mid - 1 if check(low): start = low + 1 else: start = low low = start high = maxx - 1 while low < high: mid = (low + high) // 2 if not check2(mid): low = mid + 1 else: high = mid - 1 if check2(low): end = low - 1 else: end = low ans = [] for i in range(start, end + 1): ans.append(i) print(len(ans)) print(*ans)
FUNC_DEF IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR RETURN BIN_OP VAR BIN_OP VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
from sys import * input = stdin.readline for _ in range(1): n, p = map(int, input().split()) a = list(map(int, input().split())) m = max(a) d = [0] * 4005 for i in a: d[i] += 1 w = [] for i in range(m - n + 1, m + 1): v = 0 for j in range(i): v += d[j] ans = 1 for j in range(i, i + n): v = v + d[j] ans = ans % p * v % p % p v -= 1 if ans % p != 0: w.append(i) print(len(w)) print(*w)
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) s = sorted(map(int, input().split())) for i in range(n): s[i] -= i mn = max(s) for i in range(n): s[i] += p - 1 mx = min(s[p - 1 :]) ans = [*range(mn, mx)] print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = sys.stdin.readline MAX = 2001 N, P = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) ans = [] for x in range(1, MAX + 1): tmp = 1 for i, a in enumerate(A): cantake = max(min(x + N - a, N) - i, 0) tmp = tmp * cantake % P if tmp != 0: ans.append(x) print(len(ans)) print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 0 ansls = [] mx = max(a) mn = max([(a[i] - i) for i in range(n)]) ansmx = -1 for j in range(p - 1, n)[::-1]: ansmx = max(ansmx, n - max(mn, a[j]) + mn - (n - j - 1)) while ansmx < p: ans += 1 ansls.append(mn) mn += 1 ansmx += 1 print(ans) print(*ansls)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = [] for x in range(1, 2001): fail = 0 pointer = 0 for i in range(n): while pointer < n - 1 and x + i - a[pointer + 1] >= 0: pointer += 1 if (pointer + 1 - i) % p == 0: fail = 1 break if x + i - a[pointer] < 0: fail = 1 break if fail == 0: ans.append(str(x)) print(len(ans)) print(" ".join(ans))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = sys.stdin.readline n, p = map(int, input().split()) A = sorted(map(int, input().split())) MAX = A[-1] start = max(A[0], MAX - (n - 1)) S = [] ind = 0 for c in range(start, MAX + 1): while ind < n and A[ind] <= c: ind += 1 S.append(ind) ANS = [] for i in range(len(S)): if S[i] >= p: break flag = 1 for j in range(i, len(S)): if S[j] - (j - i) >= p or S[j] - (j - i) <= 0: flag = 0 break if flag: ANS.append(start + i) print(len(ANS)) print(*ANS)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def fa(a, x, p): k = x wr = 0 for i in range(len(a)): if a[i] <= k: wr += 1 else: nk = wr // p * p wr -= a[i] - k if wr < nk: return False k = a[i] if wr < 0: return False wr += 1 if wr >= p: return False else: return True def solve(): n, p = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() ans = [] for x in range(max(max(lst) + 1, p + 1)): if fa(lst, x, p): ans.append(x) print(len(ans)) print(*ans) for i in range(1): solve()
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
from sys import stdin, stdout def asterism(n, p, a): res = [] a.sort() l = a[n - 1] for i in range(n - 1, -1, -1): l = max(a[i], l) l -= 1 l += 1 minl = l if check(bs(minl, a), minl, a, p): return res h = max(minl, a[n - 1] - 1) while l < h: m = (l + h + 1) // 2 idx = bs(m, a) if not check(idx, m, a, p): l = m else: h = m - 1 for i in range(minl, l + 1): res.append(i) return res def check(idx, v, a, p): for i in range(len(a)): if idx + 1 - i >= p: return True v += 1 idx += 1 if idx == len(a): break while idx < len(a) and a[idx] <= v: idx += 1 idx -= 1 return False def bs(v, a): l = 0 h = len(a) - 1 while l < h: m = (l + h + 1) // 2 if a[m] > v: h = m - 1 else: l = m return l n, p = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) res = asterism(n, p, a) stdout.write(str(len(res)) + "\n") if len(res) > 0: stdout.write(" ".join(map(str, res)) + "\n")
FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
from sys import stdin input = stdin.readline n, p = list(map(int, input().split())) c = list(map(int, input().split())) dobre = [] for x in range(1, 2001): dobry = True miejsca = [] for i in range(n): eps = max(c[i] - x, 0) cyk = max(n - eps, 0) miejsca.append(cyk) if min(miejsca) == 0: continue conajmniej = [0] * (n + 1) zajete = [0] * (n + 1) for i in miejsca: zajete[n - i] += 1 sumapref = 0 for i in range(n + 1): j = n - i sumapref += zajete[i] conajmniej[j] = sumapref for i in range(n): j = n - i if conajmniej[j] - i >= p or conajmniej[j] - i <= 0: dobry = False break if dobry: dobre.append(x) print(len(dobre)) print(*dobre)
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
from sys import stdin, stdout def main(): n, p = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) a.sort() factp = [1] * p for i in range(2, p): factp[i] = factp[i - 1] * i % p mxm = max(a) ht = [0] * (mxm + 1) for elem in a: ht[elem] = ht[elem] + 1 for i in range(1, mxm + 1): ht[i] += ht[i - 1] x = [False] * mxm start = max(mxm - n + 1, 1) for cand in range(start, mxm): ans = ht[cand] delta = 1 for delta in range(1, n - 1): ans = ans * (ht[min(cand + delta, mxm)] - delta) % p delta = delta + 1 if ans != 0: x[cand] = True stdout.write(str(x.count(True))) stdout.write("\n") res = [] for i in range(start, mxm): if x[i]: res.append(str(i)) stdout.write(" ".join(res)) stdout.write("\n") return main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) l = list(map(int, input().split())) l.sort() startno = l[-1] - n + 1 ans = [] for i in range(startno, l[-1] + 1): ind = 0 flag = True for j in range(n): while ind < n and l[ind] <= i + j: ind += 1 if ind >= n: if p <= n - j: flag = False break if (ind - j) % p == 0: flag = False break if flag == True: ans.append(i) print(len(ans)) ans.sort() print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = sys.stdin.readline n, p = map(int, input().split()) A = sorted(map(int, input().split())) MAX = A[-1] start = max(A[0], MAX - (n - 1)) S = [] ind = 0 for c in range(start, MAX + 1): while ind < n and A[ind] <= c: ind += 1 S.append(ind) SS = [(S[i] - i) for i in range(len(S))] MAX = 10**9 MIN = 0 for i in range(len(S)): if SS[i] <= 0: MIN = max(MIN, 1 - SS[i]) elif p - 1 - S[i] + i < i: MAX = min(MAX, p - 1 - S[i] + i) ANS = [] for i in range(MIN, MAX + 1): ANS.append(start + i) print(len(ANS)) print(*ANS)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = lambda: sys.stdin.readline().rstrip() n, p = map(int, input().split()) A = sorted([int(i) for i in input().split()]) st = A[0] gl = 2001 Ans = [] for i in range(st, gl): for j, a in enumerate(A): if i + j < a or min(j + 1, i + j - a + 1) >= p: break else: Ans.append(i) print(len(Ans)) print(*Ans)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys lines = sys.stdin.readlines() n, p = map(int, lines[0].strip().split(" ")) arr = list(map(int, lines[1].strip().split(" "))) arr.sort() counter = {} for a in arr: if a not in counter: counter[a] = 0 counter[a] += 1 lower = max(arr[-1] - n + 1, 1) l, r = lower - 1, arr[-1] + 1 def check(val): pt = 0 cnt = 0 while pt < n and arr[pt] <= val: cnt += 1 pt += 1 if cnt >= p: return False while cnt > 0: val += 1 cnt -= 1 if val in counter: cnt += counter[val] if cnt >= p: return False if val >= arr[-1]: break return not (cnt <= 0 or val < arr[-1]) cnt = 0 res = [] for i in range(lower, arr[-1] + 1): if check(i): cnt += 1 res.append(i) print(cnt) print(" ".join(map(str, res)))
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) i = min(a) j = max(a) ans = 0 b = [] while i < j: k = 0 f = 1 while k < n: if a[k] <= i: s = n else: s = n + i - a[k] s -= k if s <= 0: f = 0 break if s % p == 0: f = 0 break k += 1 if f: ans += 1 b += (i,) i += 1 print(ans) print(*b)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def smallest_winner(matrix, starting_x, x): for m in matrix: if m > x: starting_x += m - x x += m - x x += 1 return starting_x def biggest_winner(matrix, p, maxi): for i in range(len(matrix)): if i + p - 1 >= len(matrix): break maxi = min(maxi, matrix[i + p - 1] - i) return maxi n, p = map(int, input().split()) matrix = sorted(list(map(int, input().split()))) res = [ i for i in range(smallest_winner(matrix, 1, 1), biggest_winner(matrix, p, matrix[-1])) ] print(len(res)) print(" ".join(map(str, res)))
FUNC_DEF FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = list(map(int, input().split())) arr = list(map(int, input().split())) arr.sort() ans = [] for i in range(1, 3001): f = 1 num = i for j in range(n): lo, hi = 0, n - 1 h = 0 while lo <= hi: m = (lo + hi) // 2 if num >= arr[m]: h = m - j + 1 lo = m + 1 else: hi = m - 1 if h % p == 0: f = 0 if arr[j] <= num: num += 1 else: f = 0 if f == 0: continue ans.append(i) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = sorted(map(int, input().split())) b = [] i = 0 while i < len(a): j = i while j < len(a) and a[j] == a[i]: j += 1 b.append((a[i], j - i)) i = j l = a[-1] - n r = a[-1] s = [0] * (r - l + n) cc = n ci = r - 1 + n for i in range(len(b) - 1, -1, -1): cj = b[i][0] while ci >= cj and ci >= l: s[ci - l] = ci - cc ci -= 1 cc -= b[i][1] while ci >= l: s[ci - l] = ci - cc ci -= 1 c = [0] * p for i in range(l, l + n): c[s[i - l] % p] += 1 ans = [] for x in range(l, r): if c[x % p] == 0: ans.append(x) c[s[x - l] % p] -= 1 c[s[x + n - l] % p] += 1 print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
from sys import stdin def bSearch(val, a): low = 0 high = len(a) - 1 while low <= high: mid = (low + high) // 2 if a[mid] > val: high = mid - 1 else: low = mid + 1 return high + 1 n, p = [int(x) for x in stdin.readline().split()] a = sorted([int(x) for x in stdin.readline().split()]) good = 0 gArr = [] for x in range(1, max(a)): nice = True for y in range(n): cool = bSearch(x + y, a) if (cool - y) % p == 0: nice = False break if nice: good += 1 gArr.append(x) print(good) print(" ".join([str(x) for x in gArr]))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys lines = sys.stdin.readlines() n, p = map(int, lines[0].strip().split(" ")) arr = list(map(int, lines[1].strip().split(" "))) arr.sort() counter = {} for a in arr: if a not in counter: counter[a] = 0 counter[a] += 1 lower = max(arr[-1] - n + 1, 1) a, b, c, d = lower - 1, -1, -1, arr[-1] + 1 def check(val): pt = 0 cnt = 0 while pt < n and arr[pt] <= val: cnt += 1 pt += 1 if cnt >= p: return 1 while cnt > 0: val += 1 cnt -= 1 if val in counter: cnt += counter[val] if cnt >= p: return 1 if val >= arr[-1]: break if cnt <= 0 or val < arr[-1]: return -1 else: return 0 exist = False while a < d - 1: mid = (a + d) // 2 res = check(mid) if res == 1: d = mid elif res == -1: a = mid else: exist = True break if exist: b = mid c = mid while a < b - 1: mid = (a + b) // 2 res = check(mid) if res == 0: b = mid else: a = mid while c < d - 1: mid = (c + d) // 2 if check(mid) == 1: d = mid else: c = mid if exist: print(c - b + 1) print(" ".join(map(str, range(b, c + 1)))) else: print(0) print()
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = lambda: sys.stdin.readline().rstrip() n, p = map(int, input().split()) A = sorted([int(i) for i in input().split()]) A = [(A[i] - int(i)) for i in range(n)] AA = [A[-1]] for i in range(n - 1): AA.append(min(AA[-1], A[n - 2 - i])) AA = AA[::-1] Ans = [] for i in range(max(A), max(A) + p + 1): if i - AA[p - 1] + 1 < p: Ans.append(i) print(len(Ans)) print(*Ans)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def is_good(a, i): for j in range(n): choices = min(n, n - a[n - j - 1] + i) - j if choices % p == 0 or choices < 0: return False return True n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() good_integers = [] for i in range(a[-1]): if is_good(a, i): good_integers.append(i) print(len(good_integers)) print(" ".join(map(str, good_integers)))
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() arr = [] for x in range(a[0], a[-1]): pretendents = [[]] bias = 0 for i in range(n): if a[i] <= x + bias: pretendents[-1].append(a[i]) else: change = a[i] - (x + bias) for __ in range(change): pretendents.append([]) pretendents[-1].append(a[i]) bias += change res = 1 num = 0 for j in pretendents: num += len(j) res *= num num -= 1 res %= p for j in range(n - len(pretendents)): res *= num res %= p num -= 1 if res % p != 0: arr.append(x) print(len(arr)) print(" ".join(map(str, arr)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = [int(x) for x in input().split()] a = [int(x) for x in input().split()] a = sorted(a) ans = [] for start in range(1, 2001): mul = 1 l = 0 for i in range(n): got = start + i while l < n and a[l] <= got: l += 1 mul = mul * (l - i) % p if mul % p != 0: ans.append(start) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def help(): n, p = map(int, input().split(" ")) arr = list(map(int, input().split(" "))) arr.sort() final = [] for x in range(1, max(arr)): value = 0 elements = [] curr = 0 j = 0 while j < n: if arr[j] <= x + value: curr += 1 j += 1 else: elements.append(curr) curr = 0 value += 1 elements.append(curr) if elements[0] == 0: continue start = 0 flag = True for i in range(len(elements)): if start < 0: break start = start + elements[i] if start % p == 0: flag = False break start -= 1 if flag and start < p: final.append(x) print(len(final)) print(*final) for _ in range(1): help()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys def LI(): return [int(x) for x in sys.stdin.readline().split()] def solve(): n, p = LI() a = LI() a.sort() ans = [] for x in range(a[0], a[-1] + 1): fx = 1 y = x j = 0 for i in range(n): while j < n and a[j] <= y: j += 1 fx *= j - i fx %= p if fx == 0: break y += 1 else: ans.append(x) print(len(ans)) print(*ans) return solve()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = [int(i) for i in input().split()] lst = [int(i) for i in input().split()] m, r = 0, float("inf") lst.sort() for i in range(n): m = max(m, lst[i] - i) if i + 1 >= p: r = min(r, lst[i] - i + p - 1) print(max(0, r - m)) print(*list(range(m, r)))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def func(length, prime): nums = sorted(map(int, input().split())) mini = max(nums[0], nums[-1] - length + 1) xs = list(range(mini, min(mini + length, nums[-1] + 1))) L = len(xs) idxs = [0] * length for i in range(L - 1, -1, -1): if xs[i] == nums[-1]: idxs[-1] = length - i break for i in range(length - 2, -1, -1): diff = nums[i + 1] - nums[i] idxs[i] = min(length, idxs[i + 1] + diff) for i in range(length): idxs[i] -= length - 1 - i res = [] for x in xs: flag = any(op % prime == 0 for op in idxs) idxs = [(n + 1 if n != i + 1 else n) for i, n in enumerate(idxs)] if flag: continue res.append(x) print(len(res)) print(" ".join(map(str, res)) if res else "") for i in range(1): n, k = map(int, input().split()) func(n, k)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
a = [int(x) for x in input().split()] enemies = [int(x) for x in input().split()] n = a[0] p = a[1] initial = max(enemies) - n + 1 i = initial c_out = "" counter = 0 ilist = [ len([(0) for x in enemies if x <= y]) for y in range(initial, max(enemies) + 1) ] while i <= max(enemies): if i > initial: ilist.append(max(ilist)) ilist.remove(ilist[0]) j = 0 ruined = 0 while j < len(ilist): if (ilist[j] - j) % p == 0: ruined = 1 break j += 1 if not ruined: c_out += str(i) + " " counter += 1 i += 1 print(counter) print(c_out)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def s(enemy_list, prime, n_enemies): good = [] enemy_list = sorted(enemy_list) i = 0 k = 0 k_list = [] while i < n_enemies: if k >= enemy_list[i]: i += 1 else: k += 1 k_list.append(i) k_list += [n_enemies] * n_enemies minimum = max(min(enemy_list), max(enemy_list) - n_enemies) for q in range(minimum - 1, len(k_list) - n_enemies): zk_list = [((k_list[q + i] - i) % prime) for i in range(n_enemies)] if 0 not in zk_list: good.append(q) return good n, p = [int(i) for i in input().split()] a = [int(i) for i in input().split()] to_print = s(a, p, n) print(len(to_print)) print(" ".join([str(i) for i in to_print]))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
N, P = map(int, input().split()) A = list(map(int, input().split())) A.sort() ans = [] for x in range(A[0], A[-1] + 1): i = 0 n = 0 b = x for _ in range(N): while i < N and A[i] <= b: i += 1 n += 1 if n % P == 0: break n -= 1 b += 1 else: ans.append(x) print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() m = max(a[i] - i for i in range(n)) M = a[p - 1] - 1 ban = [(0) for i in range(p)] ans = [] query = [(a[i] - 1 - i, 1, -100) for i in range(n)] for x in range(m, M + 1): query.append((x, 0, -100)) for i in range(n): query.append((a[i], -1, i)) query.sort() for val, q, id in query: if q == -1: r = (val - id - 1) % p ban[r] -= 1 elif q == 0: if ban[val % p] == 0: ans.append(val) else: ban[val % p] += 1 ans.sort() print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() left = 0 right = 10**9 + 1 while right - left > 1: mid = left + (right - left) // 2 x = mid flag = 1 for i in range(n): if a[i] <= x: x += 1 else: flag = 0 break if flag: right = mid else: left = mid ansleft = right left = 0 right = 10**9 + 1 while right - left > 1: mid = left + (right - left) // 2 x = mid flag = 1 r = 0 for i in range(n): while r < n: if a[r] <= x: r += 1 else: break if r - i >= p: flag = 0 break x += 1 if flag: left = mid else: right = mid ansright = left ans = [i for i in range(ansleft, ansright + 1)] print(len(ans)) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys input = sys.stdin.readline n, p = map(int, input().split()) a = list(map(int, input().split())) a.sort() mn = 0 mx = 2000 for i in range(n): d = a[i] - i mn = max(d, mn) if i >= p - 1: d2 = a[i] - i + p - 1 mx = min(mx, d2) print(max(mx - mn, 0)) for i in range(mn, mx): print(i, end=" ")
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def main(): n, p = [int(i) for i in input().split()] a = [int(elem) for i, elem in enumerate(input().split())] a = sorted(a) ans = [] mx = a[n - 1] base = a[0] for i in range(base, mx): flag = True for j in range(n): if i + j < a[j]: flag = False break if j + p - 1 < n and i + j - a[j + p - 1] >= 0 or i >= a[j] and j >= p - 1: flag = False break if flag: ans.append(i) print(len(ans)) print(" ".join(str(i) for i in ans)) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
import sys INF = 10**18 MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() YesNo = lambda b: bool([print("Yes")] if b else print("No")) YESNO = lambda b: bool([print("YES")] if b else print("NO")) int1 = lambda x: int(x) - 1 class BIT: def __init__(self, n): self.num = n self.dat = [0] * (self.num + 1) def add(self, i, x): i += 1 while i <= self.num: self.dat[i] += x i += i & -i def sum(self, i): i += 1 s = 0 while i > 0: s += self.dat[i] i -= i & -i return s N, P = map(int, input().split()) a = tuple(map(int, input().split())) b = BIT(2001) for x in a: b.add(x, 1) ans = 0 l = [] for x in range(2001): for i in range(N): if (b.sum(min(x + i, 2000)) - i) % P == 0: break else: ans += 1 l.append(x) print(ans) print(*l)
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = map(int, input().split()) l = list(map(int, input().split())) l.sort() m = l[-1] b = [0] * (2 * n - 1) ind = 0 for i in range(2 * n - 1): while ind < n and l[ind] <= i + m - n + 1: ind += 1 b[i] = ind chuje = [0] * p for i in range(m - n + 1, m + 1): chuje[(i - b[i - m + n - 1]) % p] += 1 dobre = [] for x in range(m - n + 1, m): if not chuje[x % p]: dobre.append(x) chuje[(x - b[x - m + n - 1]) % p] -= 1 chuje[(x + n - b[x - m + 2 * n - 1]) % p] += 1 print(len(dobre)) print(*dobre)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
def smallest_winner(matrix): starting_x = 1 x = 1 for m in matrix: if m > x: starting_x += m - x x += m - x x += 1 return starting_x def biggest_winner(matrix, p): maxi = matrix[-1] for i in range(len(matrix)): if i + p - 1 >= len(matrix): break temp = matrix[i + p - 1] - i maxi = min(maxi, temp) return maxi def check_multiple(matrix): count = 0 maxi = 0 for i in range(1, len(matrix)): if matrix[i] == matrix[i - 1]: count += 1 else: count = 1 maxi = max(maxi, count) return maxi def solve(n, p, matrix): matrix = sorted(matrix) min_x = smallest_winner(matrix) max_x = biggest_winner(matrix, p) - 1 return [i for i in range(min_x, max_x + 1)] n, p = map(int, input().split()) matrix = map(int, input().split()) res = solve(n, p, matrix) print(len(res)) print(" ".join(map(str, res)))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved. First, Aoi came up with the following idea for the competitive programming problem: Yuzu is a girl who collecting candies. Originally, she has $x$ candies. There are also $n$ enemies numbered with integers from $1$ to $n$. Enemy $i$ has $a_i$ candies. Yuzu is going to determine a permutation $P$. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\{2,3,1,5,4\}$ is a permutation, but $\{1,2,2\}$ is not a permutation ($2$ appears twice in the array) and $\{1,3,4\}$ is also not a permutation (because $n=3$ but there is the number $4$ in the array). After that, she will do $n$ duels with the enemies with the following rules: If Yuzu has equal or more number of candies than enemy $P_i$, she wins the duel and gets $1$ candy. Otherwise, she loses the duel and gets nothing. The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $P$ exist? This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea: Let's define $f(x)$ as the number of valid permutations for the integer $x$. You are given $n$, $a$ and a prime number $p \le n$. Let's call a positive integer $x$ good, if the value $f(x)$ is not divisible by $p$. Find all good integers $x$. Your task is to solve this problem made by Akari. -----Input----- The first line contains two integers $n$, $p$ $(2 \le p \le n \le 2000)$. It is guaranteed, that the number $p$ is prime (it has exactly two divisors $1$ and $p$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 2000)$. -----Output----- In the first line, print the number of good integers $x$. In the second line, output all good integers $x$ in the ascending order. It is guaranteed that the number of good integers $x$ does not exceed $10^5$. -----Examples----- Input 3 2 3 4 5 Output 1 3 Input 4 3 2 3 5 6 Output 2 3 4 Input 4 3 9 1 1 1 Output 0 -----Note----- In the first test, $p=2$. If $x \le 2$, there are no valid permutations for Yuzu. So $f(x)=0$ for all $x \le 2$. The number $0$ is divisible by $2$, so all integers $x \leq 2$ are not good. If $x = 3$, $\{1,2,3\}$ is the only valid permutation for Yuzu. So $f(3)=1$, so the number $3$ is good. If $x = 4$, $\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$ are all valid permutations for Yuzu. So $f(4)=4$, so the number $4$ is not good. If $x \ge 5$, all $6$ permutations are valid for Yuzu. So $f(x)=6$ for all $x \ge 5$, so all integers $x \ge 5$ are not good. So, the only good number is $3$. In the third test, for all positive integers $x$ the value $f(x)$ is divisible by $p = 3$.
n, p = list(map(int, input().split())) arr = list(map(int, input().split())) arr.sort() x = arr[-1] y = arr[-1] - n + 1 array = [0] * n lis = [([0] * n) for i in range(n)] for i in range(n): for j in range(i + 1, n): lis[i][j] = arr[j] - arr[i] for i in range(n): s = 0 for j in range(n): if y + i + j < arr[j]: s += 1 break if s == 1: array[i] = -1 else: t = 0 for j in range(n): if y + i >= arr[j]: t += 1 num = [t] k = 0 for j in range(1, n): t -= 1 while t + j < n and y + i + j >= arr[t + j]: t += 1 num.append(t) for j in range(n): if num[j] % p == 0: array[i] = -1 break z = 0 ans = [] for i in range(n): if array[i] == -1: continue else: z += 1 ans.append(y + i) print(z) print(" ".join(str(x) for x in ans))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Tennis is a popular game. Consider a simplified view of a tennis game from directly above. The game will appear to be played on a 2 dimensional rectangle, where each player has his own court, a half of the rectangle. Consider the players and the ball to be points moving on this 2D plane. The ball can be assumed to always move with fixed velocity (speed and direction) when it is hit by a player. The ball changes its velocity when hit by the other player. And so on, the game continues. Chef also enjoys playing tennis, but in n+1$n + 1$ dimensions instead of just 3. From the perspective of the previously discussed overhead view, Chef's court is an n$n$-dimensional hyperrectangle which is axis-aligned with one corner at (0,0,0,…,0)$(0, 0, 0, \dots, 0)$ and the opposite corner at (l1,l2,l3,…,ln$(l_1, l_2, l_3, \dots, l_n$). The court of his opponent is the reflection of Chef's court across the nβˆ’1$n - 1$ dimensional surface with equation x1=0$x_1 = 0$. At time t=0$t=0$, Chef notices that the ball is at position (0,b2,…,bn)$(0, b_2, \dots, b_n)$ after being hit by his opponent. The velocity components of the ball in each of the n$n$ dimensions are also immediately known to Chef, the component in the ith$i^{th}$ dimension being vi$v_i$. The ball will continue to move with fixed velocity until it leaves Chef's court. The ball is said to leave Chef's court when it reaches a position strictly outside the bounds of Chef's court. Chef is currently at position (c1,c2,…,cn)$(c_1, c_2, \dots, c_n)$. To hit the ball back, Chef must intercept the ball before it leaves his court, which means at a certain time the ball's position and Chef's position must coincide. To achieve this, Chef is free to change his speed and direction at any time starting from time t=0$t=0$. However, Chef is lazy so he does not want to put in more effort than necessary. Chef wants to minimize the maximum speed that he needs to acquire at any point in time until he hits the ball. Find this minimum value of speed smin$s_{min}$. Note: If an object moves with fixed velocity β†’v$\vec{v}$ and is at position β†’x$\vec{x}$ at time 0$0$, its position at time t$t$ is given by β†’x+β†’vβ‹…t$\vec{x} + \vec{v} \cdot t$. -----Input----- - The first line contains t$t$, the number of test cases. t$t$ cases follow. - The first line of each test case contains n$n$, the number of dimensions. - The next line contains n$n$ integers l1,l2,…,ln$l_1, l_2, \dots, l_n$, the bounds of Chef's court. - The next line contains n$n$ integers b1,b2,…,bn$b_1, b_2, \dots, b_n$, the position of the ball at t=0$t=0$. - The next line contains n$n$ integers v1,v2,…,vn$v_1, v_2, \dots, v_n$, the velocity components of the ball. - The next line contains n$n$ integers, c1,c2,…,cn$c_1, c_2, \dots, c_n$, Chef's position at t=0$t=0$. -----Output----- - For each test case, output a single line containing the value of smin$s_{min}$. Your answer will be considered correct if the absolute error does not exceed 10βˆ’2$10^{-2}$. -----Constraints----- - 1≀t≀1500$1 \leq t \leq 1500$ - 2≀n≀50$2 \leq n \leq 50$ - 1≀li≀50$1 \leq l_i \leq 50$ - 0≀bi≀li$0 \leq b_i \leq l_i$ and b1=0$b_1 = 0$ - βˆ’10≀vi≀10$-10 \leq v_i \leq 10$ and v1>0$v_1 > 0$ - 0≀ci≀li$0 \leq c_i \leq l_i$ - It is guaranteed that the ball stays in the court for a non-zero amount of time. -----Sample Input----- 2 2 3 4 0 2 2 -2 2 2 3 10 10 10 0 0 0 1 1 1 5 5 5 -----Sample Output----- 2.0000 0.0000 -----Explanation----- Case 1: The court is 2-dimentional. The ball's trajectory is marked in red. For Chef it is optimal to move along the blue line at a constant speed of 2 until he meets the ball at the boundary. Case 2: The court is 3-dimensional and the ball is coming straight at Chef. So it is best for Chef to not move at all, thus smin=0$s_{min} = 0$.
EPS = 1e-08 for t in range(int(input())): n = int(input()) l = list(map(int, input().split())) b = list(map(int, input().split())) v = list(map(int, input().split())) c = list(map(int, input().split())) t_exit = l[0] / v[0] for i in range(1, n): if v[i] > 0: t_exit = min(t_exit, (l[i] - b[i]) / v[i]) elif v[i] < 0: t_exit = min(t_exit, -b[i] / v[i]) p = sum((b[i] - c[i]) ** 2 for i in range(n)) q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n)) r = sum(vi**2 for vi in v) func = lambda t: p / t / t + q / t + r def method1(): if b == c: return 0 lo, hi = 0, t_exit while hi - lo > EPS: d = (hi - lo) / 3 m1 = lo + d m2 = m1 + d if func(m1) <= func(m2): hi = m2 else: lo = m1 return max(0, func(lo)) ** 0.5 ans = method1() print("%.12f" % (ans,))
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are two types of vaccines available: Covaxin and Covishield. A black marketeer has X coins and wants to buy as many vaccines as possible. Due to the black marketing concerns, government has enforced the following policy: i^{th} dose of Covaxin costs a + (i - 1)\cdot b coins for every i β‰₯ 1. i^{th} dose of Covishield costs c + (i - 1)\cdot d coins for every i β‰₯ 1. The values of the four parameters a, b, c and d, however isn't constant and might vary from query to query. In general the value of these four parameters for i^{th} query will be A_{i}, B_{i}, C_{i} and D_{i} respectively. Let ans_{i} be the maximum total quantity of vaccines the black marketeer can buy corresponding to the i^{th} query. For each query, you have to find the value of ans_{i}. You will be given integers A_{1}, B_{1}, C_{1}, D_{1}, P, Q, R, S, T and M which will define the queries to be followed. For i β‰₯ 1 and i ≀ I - 1: A_{i+1} = (A_{i} + ans_{i}\cdot T) \bmod M + P B_{i+1} = (B_{i} + ans_{i}\cdot T) \bmod M + Q C_{i+1} = (C_{i} + ans_{i}\cdot T) \bmod M + R D_{i+1} = (D_{i} + ans_{i}\cdot T) \bmod M + S . Note: Since the output is large, prefer using fast input-output methods. ------ Input Format ------ - First line contains of input contains an integer I denoting the number of queries. - Second line of input contains five integers X, A_{1}, B_{1}, C_{1}, D_{1}. - Third line of input contains six integers P, Q, R, S, T, M. ------ Output Format ------ For each query output the maximum quantity of vaccines the black marketeer can buy. ------ Constraints ------ $1 ≀ I ≀ 5 \cdot 10^{5}$ $1 ≀ X,A_{1},B_{1},C_{1},D_{1} ≀ 10^{18}$ $1 ≀ P,Q,R,S,M ≀ 10^{18}$ $1 ≀ T ≀ 10^{9}$ ------ subtasks ------ Subtask #1 (10 points): $1 ≀ I ≀ 10^{3}$ $1 ≀ X ≀ 10^{9}$ Time limit: $1$ sec Subtask #2 (30 points): $1 ≀ I ≀ 10^{3}$ $1 ≀ X ≀ 10^{15}$ $10^{9} ≀ A_{1} ≀ 10^{18}$ $10^{9} ≀ B_{1} ≀ 10^{18}$ $10^{9} ≀ P ≀ 10^{18}$ $10^{9} ≀ Q ≀ 10^{18}$ Time limit: $1$ sec Subtask #3 (60 points): Original constraints Time limit: $3$ sec ----- Sample Input 1 ------ 3 20 2 3 4 1 3 7 8 4 11 20 ----- Sample Output 1 ------ 4 1 2 ----- explanation 1 ------ Test case $1$: - For the first query, $[a, b, c, d] = [A_{1}, B_{1}, C_{1}, D_{1}] = [2, 3, 4, 1]$. It is optimal to buy $2$ doses of Covaxin $(2+5=7)$ and $2$ doses of Covishield $(4+5=9)$. So the total money spent is $7+9=16$ and now the black marketeer cannot buy any more doses. So the answer is 4. - For the second query, $[a, b, c, d] = [A_{2}, B_{2}, C_{2}, D_{2}] = [(2 + 11\cdot 4)\bmod 20 + 3, (3 + 11\cdot 4) \bmod 20 + 7, (4 + 11\cdot 4) \bmod 20 + 8, (1 + 11\cdot 4) \bmod 20 + 4]=[9, 14, 16, 9]$. - For the third and the last query, $[a, b, c, d] = [A_{3}, B_{3}, C_{3}, D_{3}] = [3, 12, 15, 4]$.
import sys import time start_time = time.time() try: sys.stdin = open("input.txt", "r") except: pass input = sys.stdin.readline I = int(input()) def check(a, b, c, d, t, x): l = 0 r = t while r >= l: m = (l + r) // 2 n = t - m p = 2 * a * m + b * m * (m - 1) q = 2 * c * n + d * n * (n - 1) u = a + (m - 1) * b v = c + (n - 1) * d if p + q <= 2 * x: return True elif u == v: return False elif u > v: r = m - 1 else: l = m + 1 return False x, a, b, c, d = map(int, input().split()) p, q, f, s, t, m = map(int, input().split()) mp = {} for i in range(I): w = a, b, c, d if w in mp: ans = mp[w] else: ans = 0 r = x // min(a, c) l = 0 while r >= l: e = (l + r) // 2 if check(a, b, c, d, e, x): l = e + 1 ans = e else: r = e - 1 mp[w] = ans print(ans) k = ans * t a += k a %= m a += p b += k b %= m b += q c += k c %= m c += f d += k d %= m d += s end_time = time.time() sys.stderr.write("Time: " + str(end_time - start_time))
IMPORT IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are two types of vaccines available: Covaxin and Covishield. A black marketeer has X coins and wants to buy as many vaccines as possible. Due to the black marketing concerns, government has enforced the following policy: i^{th} dose of Covaxin costs a + (i - 1)\cdot b coins for every i β‰₯ 1. i^{th} dose of Covishield costs c + (i - 1)\cdot d coins for every i β‰₯ 1. The values of the four parameters a, b, c and d, however isn't constant and might vary from query to query. In general the value of these four parameters for i^{th} query will be A_{i}, B_{i}, C_{i} and D_{i} respectively. Let ans_{i} be the maximum total quantity of vaccines the black marketeer can buy corresponding to the i^{th} query. For each query, you have to find the value of ans_{i}. You will be given integers A_{1}, B_{1}, C_{1}, D_{1}, P, Q, R, S, T and M which will define the queries to be followed. For i β‰₯ 1 and i ≀ I - 1: A_{i+1} = (A_{i} + ans_{i}\cdot T) \bmod M + P B_{i+1} = (B_{i} + ans_{i}\cdot T) \bmod M + Q C_{i+1} = (C_{i} + ans_{i}\cdot T) \bmod M + R D_{i+1} = (D_{i} + ans_{i}\cdot T) \bmod M + S . Note: Since the output is large, prefer using fast input-output methods. ------ Input Format ------ - First line contains of input contains an integer I denoting the number of queries. - Second line of input contains five integers X, A_{1}, B_{1}, C_{1}, D_{1}. - Third line of input contains six integers P, Q, R, S, T, M. ------ Output Format ------ For each query output the maximum quantity of vaccines the black marketeer can buy. ------ Constraints ------ $1 ≀ I ≀ 5 \cdot 10^{5}$ $1 ≀ X,A_{1},B_{1},C_{1},D_{1} ≀ 10^{18}$ $1 ≀ P,Q,R,S,M ≀ 10^{18}$ $1 ≀ T ≀ 10^{9}$ ------ subtasks ------ Subtask #1 (10 points): $1 ≀ I ≀ 10^{3}$ $1 ≀ X ≀ 10^{9}$ Time limit: $1$ sec Subtask #2 (30 points): $1 ≀ I ≀ 10^{3}$ $1 ≀ X ≀ 10^{15}$ $10^{9} ≀ A_{1} ≀ 10^{18}$ $10^{9} ≀ B_{1} ≀ 10^{18}$ $10^{9} ≀ P ≀ 10^{18}$ $10^{9} ≀ Q ≀ 10^{18}$ Time limit: $1$ sec Subtask #3 (60 points): Original constraints Time limit: $3$ sec ----- Sample Input 1 ------ 3 20 2 3 4 1 3 7 8 4 11 20 ----- Sample Output 1 ------ 4 1 2 ----- explanation 1 ------ Test case $1$: - For the first query, $[a, b, c, d] = [A_{1}, B_{1}, C_{1}, D_{1}] = [2, 3, 4, 1]$. It is optimal to buy $2$ doses of Covaxin $(2+5=7)$ and $2$ doses of Covishield $(4+5=9)$. So the total money spent is $7+9=16$ and now the black marketeer cannot buy any more doses. So the answer is 4. - For the second query, $[a, b, c, d] = [A_{2}, B_{2}, C_{2}, D_{2}] = [(2 + 11\cdot 4)\bmod 20 + 3, (3 + 11\cdot 4) \bmod 20 + 7, (4 + 11\cdot 4) \bmod 20 + 8, (1 + 11\cdot 4) \bmod 20 + 4]=[9, 14, 16, 9]$. - For the third and the last query, $[a, b, c, d] = [A_{3}, B_{3}, C_{3}, D_{3}] = [3, 12, 15, 4]$.
I = int(input()) x, a, b, c, d = map(int, input().split()) p, q, r, s, t, m = map(int, input().split()) def cost_vaccine(a, b, i): return a * i + b * i * (i - 1) / 2 for _ in range(I): k = (2 * (a - c) + (d - b)) / (2 * d) a1 = b**2 / d + b a2 = 2 * a + 2 * b * c / d - 2 * b + 2 * k * b a3 = d * k**2 + 2 * k * c - k * d - 2 * x i = (-a2 + (a2**2 - 4 * a1 * a3) ** 0.5) / (2 * a1) j = k + b / d * i i = max(int(i), 0) j = max(int(j), 0) cost_i = cost_vaccine(a, b, i) cost_j = cost_vaccine(c, d, j) while cost_i > x and i > 0: i -= 1 cost_i = cost_vaccine(a, b, i) while cost_j > x and j > 0: j -= 1 cost_j = cost_vaccine(c, d, j) cost_i = cost_vaccine(a, b, i) cost_j = cost_vaccine(c, d, j) money_left = x - cost_i - cost_j while min(a + i * b, c + j * d) <= money_left: money_left -= min(a + i * b, c + j * d) if a + i * b < c + j * d: i += 1 elif c + j * d < a + i * b: j += 1 elif d < b: j += 1 else: i += 1 ans = i + j print(ans) a = (a + ans * t) % m + p b = (b + ans * t) % m + q c = (c + ans * t) % m + r d = (d + ans * t) % m + s
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR WHILE FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = sorted([[a[i] * b[i], b[i]] for i in range(n)], key=lambda x: x[0]) def find(i1, i2): if i1 > i2: return i1 mid = (i1 + i2) // 2 ss = m - sum( [ ((i[0] - mid) // i[1] + (1 if (i[0] - mid) % i[1] else 0)) for i in c if i[0] > mid ] ) return find(mid + 1 if ss < 0 else i1, i2 if ss < 0 else mid - 1) print(find(0, c[-1][0] + 1))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def find(A, B, N, M, k): for i in range(N): b = max(0, A[i] - k // B[i]) M -= b return M >= 0 def binary(A, B, N, M): low = 0 high = 10**18 while low < high: mid = (low + high) // 2 if find(A, B, N, M, mid): high = mid else: low = mid + 1 if find(A, B, N, M, mid): return mid else: return high N, M = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) if M >= sum(A): ans = 0 elif M == 0: ans = 0 for i in range(N): ans = max(ans, A[i] * B[i]) else: ans = binary(A, B, N, M) print(ans)
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
n, m = [int(x) for x in input().split()] a, b = [], [] ma, mb = 0, 0 for x in input().split(): a.append(int(x)) if ma < int(x): ma = int(x) for x in input().split(): b.append(int(x)) if mb < int(x): mb = int(x) l = 0 r = ma * mb while l <= r: mid = (r - l) // 2 + l k = 0 for i in range(n): j = mid // b[i] k += max(0, a[i] - j) if k <= m: ans = mid r = mid - 1 else: l = mid + 1 print(int(ans))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) lo, hi = 0, 0 for i in range(n): hi += a[i] * b[i] def check(mid): x = 0 for i in range(n): x += max(a[i] - mid // b[i], 0) if x <= m: return True return False while lo <= hi: mid = (lo + hi) // 2 if check(mid): res = mid hi = mid - 1 else: lo = mid + 1 print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def chk(mid, A, B, C, n, c): count = 0 for i in range(n): if C[i] > mid: count += A[i] - mid // B[i] if count <= c: return True return False for _ in range(1): n, c = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [(A[i] * B[i]) for i in range(0, n)] start = 0 end = max(C) answer = -1 while start <= end: mid = (start + end) // 2 if chk(mid, A, B, C, n, c): answer = mid end = mid - 1 else: start = mid + 1 print(answer)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def succeed(mid, m): d = mid z = m k = 0 for i in range(n): if a[i] * b[i] > d: v = a[i] * b[i] - d if v % b[i]: u = v // b[i] + 1 else: u = v // b[i] z -= u if z < 0: k = 1 break if k: return 0 else: return 1 def bsea(l, r, m): while r - l > 1: mid = (l + r) // 2 if succeed(mid, m): r = mid else: l = mid return r n, m = [int(x) for x in input().strip().split(" ")] a = [int(x) for x in input().strip().split(" ")] b = [int(x) for x in input().strip().split(" ")] max = 0 s = 0 for i in range(n): s += a[i] if a[i] * b[i] > max: max = a[i] * b[i] if s <= m: print(0) else: l = 0 r = max print(bsea(l, r, m))
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
t = input().split() N = int(t[0]) M = int(t[1]) candies_list = [] balloon_list = [] balloons = input().split() candies = input().split() low = 0 mid = 0 max_val = 0 for i in range(N): balloon_list.append(int(balloons[i])) for i in range(N): candies_list.append(int(candies[i])) for i in range(N): cost = balloon_list[i] * candies_list[i] if cost > max_val: max_val = cost high = max_val while low < high: mid = (low + high) // 2 bal_count = 0 for i in range(N): bal_count += max(0, balloon_list[i] - mid // candies_list[i]) if bal_count <= M: high = mid else: low = mid + 1 print(low)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
n, m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] L, R = 0, 10**20 while L < R: mid = (L + R) // 2 temp = m for i in range(n): temp -= max(0, a[i] - mid // b[i]) if temp < 0: L = mid + 1 else: R = mid print(L)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def check(mid): s = 0 for i in range(n): curr = max(0, a[i] - mid // b[i]) s += curr return s n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) low = 0 high = max(a) * max(b) while low <= high: mid = (low + high) // 2 val = check(mid) if val <= m: res = mid high = mid - 1 else: low = mid + 1 print(res)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def good(maxcan, n, m, balls, cand): cntballons = 0 for i in range(n): ball_Onday = balls[i] - maxcan // cand[i] cntballons += max(0, ball_Onday) if cntballons > m: return False return True def minCandiesAppy(n, m, balloons, candies): left = 0 right = 0 for i in range(n): temp = balloons[i] * candies[i] if temp > right: right = temp ans = 0 while left <= right: mid = (left + right) // 2 if good(mid, n, m, balloons, candies): ans = mid right = mid - 1 else: left = mid + 1 return ans n, m = map(int, input().split()) balloons = list(map(int, input().split())) candies = list(map(int, input().split())) print(minCandiesAppy(n, m, balloons, candies))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def balloons(a, b, candy): total = 0 for ai, bi in zip(a, b): if bi == 0: continue else: total += max(ai - candy // bi, 0) return total def main(): n, m = map(int, input().strip().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) left, right = 0, max(a) * max(b) while left < right: mid = (left + right) // 2 balloons_needed = balloons(a, b, mid) if balloons_needed <= m: right = mid else: left = mid + 1 print(left) main()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def ans(a, b, n, m, mid, c): i = 0 count = 0 while i < n: if c[i] > mid: count += a[i] - mid // b[i] if m < count: return False i += 1 return True n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for i in range(n): c.append(a[i] * b[i]) low = 0 high = max(c) mid = low + (high - low) // 2 while low < high: if ans(a, b, n, m, mid, c) == True: high = mid elif ans(a, b, n, m, mid, c) == False: low = mid + 1 mid = low + (high - low) // 2 print(mid)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [(a[i] * b[i]) for i in range(n)] ans = 0 lo = 0 hi = max(c) while lo <= hi: mid = (lo + hi) // 2 bal = 0 for i in range(n): if b[i] == 0: continue bal += max(0, a[i] - mid // b[i]) if bal <= m: ans = mid hi = mid - 1 else: lo = mid + 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def bal_needed(a, b, candies): c = 0 for i in range(len(a)): if b[i] == 0: continue c += max(a[i] - candies // b[i], 0) return c def solve(a, b, n, m): right, left = 0, 0 for i in range(n): right = max(right, a[i] * b[i]) while left < right: mid = (left + right) // 2 bal = bal_needed(a, b, mid) if bal <= m: right = mid else: left = mid + 1 return left n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) print(solve(a, b, n, m))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def check(a, b, mid, m, n): temp = 0 for i in range(n): if a[i] * b[i] > mid: temp += a[i] - mid // b[i] if m < temp: return 0 return 1 n, m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] start = 0 end = start for i in range(n): end = max(end, a[i] * b[i]) ans = 0 while start <= end: mid = (start + end) // 2 if check(a, b, mid, m, n): end = mid - 1 ans = mid else: start = mid + 1 print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number of balloons Appy wants on day $i$ by $A_{i}$. The problem is that you only have $M$ balloons. Fortunately, you can give her candies instead of balloons as well. On each day $i$, Appy accepts $B_{i}$ candies per each balloon you do not give her β€” formally, if you give Appy $X_{i}$ balloons on day $i$, then you have to give her $C_{i} = \mathrm{max}(0, A_{i} - X_{i}) \cdot B_{i}$ candies as well. Your task is to minimize the maximum number of candies you give Appy on some day β€” find the minimum possible value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$. The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$. ------ Output ------ Print a single line containing one integer β€” the minimum value of $\mathrm{max}(C_{1}, C_{2}, C_{3}, ..., C_{N})$. ------ Constraints ------ $1 ≀ N ≀ 10^{5}$ $0 ≀ M ≀ 10^{18}$ $0 ≀ A_{i} ≀ 10^{9}$ for each valid $i$ $0 ≀ B_{i} ≀ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (27 points): $1 ≀ A_{i} ≀ 10$ for each valid $i$ $1 ≀ B_{i} ≀ 10$ for each valid $i$ Subtask #2 (73 points): original constraints ----- Sample Input 1 ------ 5 3 1 2 3 4 5 1 2 3 4 5 ----- Sample Output 1 ------ 15 ----- explanation 1 ------ If you give Appy $0, 0, 0, 1, 2$ balloons on days $1$ through $5$, then the required numbers of candies on each day are $1, 4, 9, 12, 15$. The maximum number of candies is $15$, required on day $5$.
def cond(n, m, a, b, x): y = 0 for i in range(n): if a[i] * b[i] > x: y += a[i] - x // b[i] if y > m: return False return True def binSearch(n, m, a, b, x): low = 0 high = x r = x while low <= high: mid = (low + high) // 2 if cond(n, m, a, b, mid): r = min(r, mid) high = mid - 1 else: low = mid + 1 return r n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) x = 0 for i in range(n): x = max(a[i] * b[i], x) print(binSearch(n, m, a, b, x))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR