description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
T = int(input()) while T: T -= 1 n = int(input()) s = list(input()) t = list(input()) ls = [] lt = [] if s[0] != t[0] or s[-1] != t[-1]: print("-1") continue for i in range(n - 1): if s[i] != s[i + 1]: ls.append(i) if t[i] != t[i + 1]: lt.append(i) if len(ls) != len(lt): print("-1") continue ans = 0 for i in range(len(ls)): ans += abs(ls[i] - lt[i]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
for _ in range(int(input())): n = int(input()) a = input() b = input() a_ = [] b_ = [] for i in range(n - 1): if a[i] != a[i + 1]: a_.append(i) if b[i] != b[i + 1]: b_.append(i) if len(a_) != len(b_) or a[0] != b[0] or a[-1] != b[-1]: print(-1) continue count = 0 for i in range(len(a_)): count += abs(a_[i] - b_[i]) print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
for _ in range(int(input())): n = int(input()) s = list(map(int, input())) t = list(map(int, input())) l1, l2 = [], [] if s[0] != t[0] or s[n - 1] != t[n - 1]: print(-1) else: for j in range(n - 1): if s[j] != s[j + 1]: l1.append(j) if t[j] != t[j + 1]: l2.append(j) if len(l1) != len(l2): print(-1) else: print(sum(abs(l1[q] - l2[q]) for q in range(len(l1))))
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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
t_ = int(input()) for _ in range(t_): n = int(input()) s = input().strip() t = input().strip() if s[0] != t[0]: print(-1) continue s_dist = [] for i in range(1, n): if s[i] != s[i - 1]: s_dist.append(i) total = 0 t_seg = 0 for i in range(1, n): if t[i] != t[i - 1]: t_seg += 1 if t_seg > len(s_dist): break total += abs(i - s_dist[t_seg - 1]) if t_seg != len(s_dist): print(-1) else: print(total)
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
for _ in range(int(input())): n = int(input()) s1 = input() s2 = input() if s1[0] == s2[0] and s1[-1] == s2[-1]: cur = s1[0] num = 0 l1 = [] l2 = [] for i in s1 + "2": if i == cur: num += 1 else: l1.append(num) num = 1 cur = i cur = s1[0] num = 0 for i in s2 + "2": if i == cur: num += 1 else: l2.append(num) num = 1 cur = i if len(l1) != len(l2): print(-1) else: ans = 0 for i in range(len(l1) - 1): ans += abs(l1[i] - l2[i]) l1[i + 1] = l1[i + 1] + l1[i] - l2[i] print(ans) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR BIN_OP VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR BIN_OP VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
t = eval(input()) for i in range(t): n = eval(input()) s1 = input() s2 = input() k1, k2 = 1, 1 for i in range(0, len(s1) - 1): if s1[i] != s1[i + 1]: k1 += 1 for i in range(0, len(s2) - 1): if s2[i] != s2[i + 1]: k2 += 1 if k1 != k2 or s1[0] != s2[0] or s1[-1] != s2[-1]: print(-1) continue l1, l2 = [], [] for i in range(0, len(s1) - 1): if s1[i] != s1[i + 1]: l1.append(i) for i in range(0, len(s2) - 1): if s2[i] != s2[i + 1]: l2.append(i) sum = 0 for i in range(len(l1)): sum += abs(l1[i] - l2[i]) print(sum)
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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
for _ in range(int(input())): n = int(input()) s = input() t = input() if s[0] != t[0] or s[-1] != t[-1]: print(-1) continue s_seg = 0 s_fl = False t_seg = 0 t_fl = False for i in range(n): if not s_fl and s[i] == "1": s_fl = True if s_fl and s[i] == "0": s_fl = False s_seg += 1 if not t_fl and t[i] == "1": t_fl = True if t_fl and t[i] == "0": t_fl = False t_seg += 1 s_seg += s_fl t_seg += t_fl if s_seg != t_seg: print(-1) continue ans = 0 s_pointer = 0 t_pointer = 0 while s_pointer < n and t_pointer < n: while t_pointer < n and t[t_pointer] != "1": t_pointer += 1 t_start = t_pointer while t_pointer < n and t[t_pointer] != "0": t_pointer += 1 t_end = t_pointer while s_pointer < n and s[s_pointer] != "1": s_pointer += 1 s_start = s_pointer while s_pointer < n and s[s_pointer] != "0": s_pointer += 1 s_end = s_pointer ans += abs(t_start - s_start) + abs(t_end - s_end) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
def miis(): return map(int, input().split()) for _ in range(int(input())): n = int(input()) s = list(map(int, list(input()))) t = list(map(int, list(input()))) l = 0 cs = [] ct = [] for i in range(n): if s[i]: if l: cs[-1][1] += 1 else: cs.append([i, i]) l = 1 else: l = 0 l = 0 for i in range(n): if t[i]: if l: ct[-1][1] += 1 l = 1 else: ct.append([i, i]) l = 1 else: l = 0 if len(ct) == len(cs) and s[0] == t[0] and s[-1] == t[-1]: ans = 0 for i in range(len(ct)): ans += abs(ct[i][0] - cs[i][0]) + abs(ct[i][1] - cs[i][1]) print(ans) else: print(-1)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
num_inp = lambda: int(input()) arr_inp = lambda: list(map(int, input().split())) sp_inp = lambda: map(int, input().split()) str_inp = lambda: input() for _ in range(int(input())): N = int(input()) S = input() T = input() s, t = [], [] for i in range(N - 1): if S[i] != S[i + 1]: s.append(i) if T[i] != T[i + 1]: t.append(i) if S[0] != T[0] or S[N - 1] != T[N - 1] or len(s) != len(t): print(-1) continue print(sum(abs(s[i] - t[i]) for i in range(len(s))))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
q = int(input()) for _ in range(q): n = int(input()) s1 = input() s2 = input() if s1[0] != s2[0] or s1[-1] != s2[-1]: print(-1) else: tmp1 = [] tmp = "" start = -1 for idx, char in enumerate(s1): if char != tmp: if tmp == "1": tmp1.append([start, idx - 1]) tmp = char start = idx if tmp == "1": tmp1.append([start, len(s1) - 1]) tmp2 = [] tmp = "" start = -1 for idx, char in enumerate(s2): if char != tmp: if tmp == "1": tmp2.append([start, idx - 1]) tmp = char start = idx if tmp == "1": tmp2.append([start, len(s2) - 1]) if len(tmp1) != len(tmp2): print(-1) else: ans = 0 for [x, y], [a, b] in zip(tmp1, tmp2): ans += abs(x - a) + abs(y - b) print(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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR LIST VAR VAR LIST VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
k = int(input()) while k: p = int(input()) s = input() t = input() a = [] b = [] ac = 0 bc = 0 for i in range(1, p): if s[i] != s[i - 1]: a.append(i) ac += 1 if t[i] != t[i - 1]: b.append(i) bc += 1 if s[0] != t[0] or ac != bc: print(-1) else: check = 0 for i in range(len(a)): check += abs(a[i] - b[i]) print(check) k -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
def f(s, t, n): if s[0] != t[0] or s[n - 1] != t[n - 1]: return -1 i, j, edits = 0, 0, 0 while True: while i < n - 1 and s[i] == s[i + 1]: i += 1 while j < n - 1 and t[j] == t[j + 1]: j += 1 if i < n - 1 and j < n - 1: edits += abs(i - j) elif i == n - 1 and j == n - 1: return edits + abs(i - j) else: return -1 i += 1 j += 1 T = int(input()) while T: n = int(input()) s, t = input(), input() print(f(s, t, n)) T -= 1
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
def find(s): st = s[0] a = [] c = 0 for i in range(len(s)): if s[i] == st: c += 1 else: a.append(c) c = 1 st = s[i] if c > 0: a.append(c) return a for _ in range(int(input())): n = input() s = input() t = input() a = find(s) b = find(t) ok = True if s[0] != t[0] or len(a) != len(b): ok = False ans = 0 l1 = r1 = l2 = r2 = 0 if ok: for i in range(len(a)): if i % 2 == 0: l1 += a[i] r1 += a[i] l2 += b[i] r2 += b[i] else: r1 += a[i] r2 += b[i] ans += abs(r2 - r1) + abs(l1 - l2) l1 += a[i] l2 += b[i] if ok: print(ans) else: print(-1)
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Mark has just purchased a rack of $n$ lightbulbs. The state of the lightbulbs can be described with binary string $s = s_1s_2\dots s_n$, where $s_i={1}$ means that the $i$-th lightbulb is turned on, while $s_i={0}$ means that the $i$-th lightbulb is turned off. Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following: Select an index $i$ from $2,3,\dots,n-1$ such that $s_{i-1}\ne s_{i+1}$. Toggle $s_i$. Namely, if $s_i$ is ${0}$, set $s_i$ to ${1}$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $t$. Help Mark determine the minimum number of operations to do so. -----Input----- The first line of the input contains a single integer $q$ ($1\leq q\leq 10^4$) — the number of test cases. The first line of each test case contains a single integer $n$ ($3\leq n\leq 2\cdot 10^5$) — the number of lightbulbs. The second line of each test case contains a binary string $s$ of length $n$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $t$ of length $n$ — the final state of the lightbulbs. It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $s$ to $t$. If there is no such sequence of operations, print $-1$. -----Examples----- Input 4 4 0100 0010 4 1010 0100 5 01001 00011 6 000101 010011 Output 2 -1 -1 5 -----Note----- In the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $i=3$, changing ${01}{{0}}{0}$ to ${01}{{1}}{0}$. Select $i=2$, changing ${0}{{1}}{10}$ to ${0}{{0}}{10}$. In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $s$. In the third test case, even though the first digits of $s$ and $t$ are the same and the last digits of $s$ and $t$ are the same, it can be shown that there is no sequence of operations that satisfies the condition. In the fourth test case, one sequence that achieves the minimum number of operations is the following: Select $i=3$, changing ${00}{{0}}{101}$ to ${00}{{1}}{101}$. Select $i=2$, changing ${0}{{0}}{1101}$ to ${0}{{1}}{1101}$. Select $i=4$, changing ${011}{{1}}{01}$ to ${011}{{0}}{01}$. Select $i=5$, changing ${0110}{{0}}{1}$ to ${0110}{{1}}{1}$. Select $i=3$, changing ${01}{{1}}{011}$ to ${01}{{0}}{011}$.
def p(s): k = 0 q = 1 for i in s: if i == "1": if q: k += 1 q = 0 else: q = 1 return k for i in range(int(input())): n = int(input()) s1 = input() s2 = input() s = 0 if s1[0] != s2[0] or s1[-1] != s2[-1] or p(s1) != p(s2): print(-1) else: l1 = l2 = r1 = r2 = 0 y = p(s1) for i in range(y): while s1[l1] != "1": l1 += 1 r1 = l1 while r1 < n and s1[r1] == "1": r1 += 1 while s2[l2] != "1": l2 += 1 r2 = l2 while r2 < n and s2[r2] == "1": r2 += 1 s += abs(l1 - l2) + abs(r1 - r2) l1 = r1 l2 = r2 print(s)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the xi coordinate. The village consists of n houses, the i-th house is located in the point with coordinates of xi. TELE3, a cellular communication provider planned to locate three base stations so as to provide every house in the village with cellular communication. The base station having power d located in the point t provides with communication all the houses on the segment [t - d, t + d] (including boundaries). To simplify the integration (and simply not to mix anything up) all the three stations are planned to possess the equal power of d. Which minimal value of d is enough to provide all the houses in the village with cellular communication. Input The first line contains an integer n (1 ≤ n ≤ 2·105) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence x1, x2, ..., xn of integer numbers (1 ≤ xi ≤ 109). It is possible that two or more houses are located on one point. The coordinates are given in a arbitrary order. Output Print the required minimal power d. In the second line print three numbers — the possible coordinates of the base stations' location. Print the coordinates with 6 digits after the decimal point. The positions of the stations can be any from 0 to 2·109 inclusively. It is accepted for the base stations to have matching coordinates. If there are many solutions, print any of them. Examples Input 4 1 2 3 4 Output 0.500000 1.500000 2.500000 3.500000 Input 3 10 20 30 Output 0 10.000000 20.000000 30.000000 Input 5 10003 10004 10001 10002 1 Output 0.500000 1.000000 10001.500000 10003.500000
import sys n = int(input()) houses = sorted(set(map(int, input().split()))) if len(houses) <= 3: print(0) result = houses[:] while len(result) < 3: result.append(result[-1]) print("%.6f %.6f %.6f" % tuple(result)) import sys sys.exit() span = 0 left = 1 right = len(houses) - 2 while houses[right] - houses[left] > span: left_gap = houses[left] - houses[0] - span right_gap = houses[-1] - houses[right] - span middle = houses[right] - houses[left] if left_gap <= right_gap: if span + left_gap > middle: span = middle break left += 1 if left_gap == right_gap: right -= 1 span += left_gap else: if span + right_gap > middle: span = middle break right -= 1 span += right_gap print("%.6f" % (span / 2)) print( "%.6f %.6f %.6f" % ( (houses[0] + houses[left - 1]) / 2, (houses[left] + houses[right]) / 2, (houses[right + 1] + houses[-1]) / 2, ) )
IMPORT 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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IMPORT EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER
The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the xi coordinate. The village consists of n houses, the i-th house is located in the point with coordinates of xi. TELE3, a cellular communication provider planned to locate three base stations so as to provide every house in the village with cellular communication. The base station having power d located in the point t provides with communication all the houses on the segment [t - d, t + d] (including boundaries). To simplify the integration (and simply not to mix anything up) all the three stations are planned to possess the equal power of d. Which minimal value of d is enough to provide all the houses in the village with cellular communication. Input The first line contains an integer n (1 ≤ n ≤ 2·105) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence x1, x2, ..., xn of integer numbers (1 ≤ xi ≤ 109). It is possible that two or more houses are located on one point. The coordinates are given in a arbitrary order. Output Print the required minimal power d. In the second line print three numbers — the possible coordinates of the base stations' location. Print the coordinates with 6 digits after the decimal point. The positions of the stations can be any from 0 to 2·109 inclusively. It is accepted for the base stations to have matching coordinates. If there are many solutions, print any of them. Examples Input 4 1 2 3 4 Output 0.500000 1.500000 2.500000 3.500000 Input 3 10 20 30 Output 0 10.000000 20.000000 30.000000 Input 5 10003 10004 10001 10002 1 Output 0.500000 1.000000 10001.500000 10003.500000
n = int(input()) a = sorted(map(int, input().split())) i = 1 - n j = n - 2 s = 0 n = a[j] - a[i] while s < n: l, r = a[i] - a[0], a[-1] - a[j] if l < r: if n <= l: s = n break i += 1 s = l else: if n <= r: s = n break j -= 1 s = r n = a[j] - a[i] s /= 2 print(s) print(s + a[0], a[j] - s, a[-1] - s)
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 NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, k = map(int, input().split()) a = [int(i) for i in input().split()] a.sort() h = a[-1] height = 0 count = 0 for i in range(n - 1): if a[i] > height: height = height + 1 count = count + 1 if height < h: print(sum(a) - (count + h - height)) else: print(sum(a) - (count + 1))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = [int(x) for x in input().split()] c = sum(a) if n == 1: print(0) exit(0) a.sort() res = 0 pocl = a[n - 1] f = False for i in range(n - 2, -1, -1): if pocl > 1: if a[i] >= pocl: res += 1 pocl -= 1 res += a[i] - 1 else: f = True pocl = a[i] res += 1 res += a[i] - 1 pocl -= 1 elif pocl == 1: if f: res += 1 res += a[i] - 1 pocl -= 1 else: res += a[i] - 1 print(res)
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) l = list(map(int, input().split())) if n == 1: print(0) else: l.sort() k = 0 ans = 0 for i in range(n): ans += 1 if l[i] > k: k += 1 ans += l[n - 1] - k print(sum(l) - 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) A = list(map(int, input().split())) sum = 0 A.sort() for i in A: sum += i choosen = 0 for i in range(n): if A[i] > choosen: choosen += 1 not_choosen = A[-1] - choosen print(sum - not_choosen - n)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
def main(): inl = input().strip().split() n, m = int(inl[0]), int(inl[1]) stacks = [] total_blocks = 0 for i, h in enumerate(input().strip().split()): stacks.append((i, int(h))) total_blocks += int(h) stacks.sort(key=lambda s: s[1], reverse=True) blocks = 0 hmax = stacks[0][1] for i in range(n - 1): c = stacks[i] if c[1] == 0: continue forced = min(c[1], hmax) - stacks[i + 1][1] if forced > 0: blocks += forced hmax = stacks[i + 1][1] else: blocks += 1 hmax -= 1 if stacks[n - 1][1] > 0: if hmax > 0: blocks += hmax else: blocks += 1 print(total_blocks - blocks) main()
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = [int(o) for o in input().split()] a = sorted(a) b = [] u = 0 s = sum(a) l = 0 k = 0 d = 0 for i in range(n): l = a[i] d += a[i] - u if d <= i: d += 1 u = a[i] print(s - d)
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 ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = list(map(int, input().split())) in_list = list(map(int, input().split())) in_list.sort() prev = 0 min_block = 0 for i in range(n): min_block = min_block + in_list[i] - prev if min_block <= i: min_block = min_block + 1 prev = in_list[i] print(sum(in_list) - min_block)
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
def run(): n, mmm = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() ans = 0 for i in range(n): if arr[i] > ans: ans += 1 left = arr[n - 1] - ans sol = sum(arr) - n - left print(sol) run()
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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = input().split() a = [int(i) for i in input().split()] a.sort() if 1 in a: c = 1 else: c = 0 ans = cc = 0 for i in range(int(n)): if a[i] == c and cc == 0 or a[i] == c + 1: ans += a[i] - 1 elif a[i] == c and cc > 0: ans += c cc -= 1 else: ans += c cc += a[i] - c - 1 c = a[i] if n == "1": print(0) else: print(ans)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) seq = sorted(map(int, input().split())) ans = 0 for i in range(n): ans += seq[i] - 1 wait = 0 last = seq[-1] for i in range(n - 1, 0, -1): wait += 1 if last - seq[i - 1] > wait: ans -= last - seq[i - 1] - wait wait = 0 last = seq[i - 1] if last - 1 > wait: ans -= last - 1 - wait wait = 0 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 NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) worst = 0 maxi = a[0] a.append(0) for i in range(n + 1): bad = maxi - a[i] - i worst = max(worst, bad) print(sum(a) - n - worst)
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 NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
a = input() n = int(a.split()[0]) m = int(a.split()[1]) b = input() l = list(map(int, b.split())) l.sort() h = 0 k = 0 for i in range(n): if h < l[n - 1] and l[i] >= h + 1: h = h + 1 k = k + 1 else: k = k + 1 k = k + l[n - 1] - h print(sum(l) - k)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = [int(s) for s in input().split()] a = sorted(a) current = a[n - 1] k = 0 if n == 1: print(0) exit() for i in range(n - 1, -1, -1): if i > 0 and a[i - 1] < current - 1: a[i] -= current - 1 - a[i - 1] k += a[i] - 1 current = a[i - 1] elif a[i] >= current: k += a[i] - current if i != 0: k += max(current - 1, 0) current -= 1 current = max(current, 1) print(k)
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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
[n, m] = [int(x) for x in input().split(" ")] A = [int(x) for x in input().split(" ")] A.sort() maxRemove = 0 maxHeight = 0 for i in range(n): if i == n - 1: if A[i] > maxHeight: maxRemove += maxHeight else: maxRemove += A[i] - 1 elif i == 0: maxHeight = 1 maxRemove += A[i] - 1 else: maxRemove += A[i] - 1 if A[i] > maxHeight: maxHeight += 1 print(maxRemove)
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) used = a[0] f = a[0] - 1 for i in range(1, n): if f > 0: f = min(f - 1, a[i] - 1) else: used += 1 print(sum(a) - used)
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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
import sys n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) ma = a[n - 1] yr = 1 g = 1 if n == 1: print(0) sys.exit() for i in range(1, n): if a[i] > yr: yr += 1 g += 1 g += ma - yr print(sum(a) - g)
IMPORT 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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
s = input().split() n = int(s[0]) m = int(s[1]) stack = list(map(int, input().split())) stack.sort() h = 0 ans = 0 for i in stack: ans += 1 if i > h: h += 1 ans += stack[-1] - h print(sum(stack) - ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) mas = list(map(int, input().split())) mas.sort() res, a = 0, mas[n - 1] for i in range(n - 2, -1, -1): q, w = mas[i + 1], mas[i] if q == w: res += q - 1 a -= 1 elif a - 1 <= w: res += q - 1 a -= 1 else: res += q - (a - w) a = w res += min(mas[0] - 1, mas[0] - a) 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 EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] s = sum(a) need = 0 a.sort() j = 1 flag = 0 k = max(a) if n == 1: print(0) else: for i in range(n): if a[i] < j: flag = 1 else: flag = 0 if a[i] == 1: need += 1 elif a[i] >= j and i != n - 1: need += 1 elif a[i] >= j and i == n - 1 and j <= k: need += k - j + 1 else: need += 1 if flag != 1: j += 1 print(s - need)
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 NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = [int(x) for x in input().split()] L = [int(x) for x in input().split()] D = {} for i in L: if i in D: D[i] += 1 else: D[i] = 1 S = sorted(D.keys(), reverse=True) + [0] height = S[0] extra = 0 for i in range(0, len(S) - 1): height -= max(D[S[i]], max(0, min(S[i], height) - S[i + 1])) print(sum(L) - S[0] + height)
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 DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER LIST NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) p = sum(a) i = n - 1 while i > 0: a[i - 1] = min(a[i] - 1, a[i - 1]) p -= a[i] - a[i - 1] i -= 1 print(p - max(a[0], 1))
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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = list(map(int, input().strip().split(" "))) a = list(map(int, input().strip().split(" "))) a.sort() x = 0 y = 0 count = 0 for i in range(0, n): count += a[i] if a[i] > y: y += 1 x += 1 if i == n - 1 and a[i] > y: x += a[i] - y print(count - x)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) l = list(map(int, input().split())) s = 0 l.sort() k = 0 for i in range(n - 1, 0, -1): if l[i] > l[i - 1]: s += l[i - 1] elif l[i] == l[i - 1] and l[i] > 1: s += l[i] l[i - 1] = l[i - 1] - 1 else: s += l[i - 1] - l[i] if l[i] > 1: s += l[i] l[i - 1] = l[i] - 1 else: l[i - 1] = l[i] print(s)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
def main(): n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) s = 0 for i in range(len(a)): s += a[i] for i in range(n - 2, -1, -1): if a[i + 1] > a[i]: s -= a[i + 1] - a[i] else: s -= 1 a[i] = max(a[i + 1] - 1, 1) print(s - a[0]) main()
FUNC_DEF 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
def solve(xs): if len(xs) == 1: return 0 heights = sorted(xs)[::-1] used = 0 needed = heights[0] for i in range(len(heights)): current = heights[i] if needed <= current: used += 1 needed -= 1 else: used += needed - current used += 1 needed = current - 1 if needed > 0: used += needed return sum(xs) - used n, m = map(int, input().split()) xs = list(map(int, input().split()))[:n] print(solve(xs))
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR RETURN BIN_OP FUNC_CALL VAR 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 VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() summ, minn = 0, 0 for i in range(n): summ += arr[i] - 1 minn = min(minn + 1, arr[i]) print(summ - arr[-1] + minn)
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 NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = [int(x) for x in input().split()] hei = [int(x) for x in input().split()] total_blocks = 0 for x in hei: total_blocks += x hei.sort(reverse=True) if len(hei) == 1: print(0) exit() used_blocks = 0 max_covered_hei = -1 for i in range(len(hei)): if max_covered_hei == -1: max_covered_hei = hei[i] used_blocks = 1 else: diff_to_cur = max(0, max_covered_hei - hei[i]) if diff_to_cur == 0: used_blocks += 1 max_covered_hei -= 1 max_covered_hei = max(0, max_covered_hei) else: used_blocks += diff_to_cur max_covered_hei = hei[i] if max_covered_hei > 1: used_blocks += max_covered_hei - 1 print(total_blocks - used_blocks)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
a, b = map(int, input().split()) list1 = [*map(int, input().split())] list1.sort(reverse=True) ans = 0 neededHeight = list1[0] for i, j in enumerate(list1[1:]): neededHeight = max(min(j, list1[i] - 1), 1) ans += j - neededHeight if list1[i] > 1: ans += neededHeight list1[i + 1] = neededHeight print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) arr = sorted(arr, reverse=True) ak = [] for i in range(n): ak.append(arr[i]) for i in range(n - 1): if arr[i] == min(arr[i], arr[i + 1]): arr[i + 1] = max(1, arr[i] - 1) ans = 0 for i in range(n): ans += ak[i] - arr[i] for i in range(n - 1): if arr[i] != 1: ans += arr[i + 1] if len(arr) > 1: if arr[n - 1] != 1: ans += arr[n - 1] - arr[n - 1] else: ans = 0 print(ans)
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
R = lambda: list(map(int, input().split())) n, m = R() a = R() a.sort() i = n - 1 re = 0 now = a[i] while i > 0: if now > a[i - 1]: now = a[i - 1] re += now elif now == a[i - 1] and now > 1: now -= 1 re += now + 1 else: if now > 1: now -= 1 re += now re += a[i - 1] - now i -= 1 print(re)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
def exponat(lst): result, count = 0, 1 for i in range(len(lst)): if count > lst[len(lst) - 1] or count > lst[i]: result += lst[i] - 1 continue if i != len(lst) - 1: result += lst[i] - 1 count += 1 else: result += count - 1 return result n, m = [int(i) for i in input().split()] a = [int(j) for j in input().split()] print(exponat(sorted(a)))
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) A = list(map(int, input().split())) k = max(A) s = sum(A) x = 0 a = 0 A.sort() for i in range(0, n): if A[i] > x: x += 1 a += 1 else: a += 1 if k > x: a += k - x print(s - a)
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 NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) l = list(map(int, input().split())) l.sort(reverse=True) sa = sum(l) t = 0 for i in range(len(l) - 1): if l[i] != 1: if l[i] > l[i + 1]: t += l[i] - l[i + 1] elif l[i] == l[i + 1]: l[i + 1] -= 1 t += 1 else: l[i + 1] = l[i] - 1 t += 1 else: t += len(l) - 1 - i l[-1] = 1 break t += l[-1] print(sa - t)
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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) arr = list(map(int, input().split())) arr.sort(reverse=True) right = arr[0] c = 0 for i in range(n): if arr[i] >= right: c += 1 right -= 1 else: c += 1 right = arr[i] - 1 if right == 0: break print(sum(arr) - (n - c) - arr[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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, t = input().split() t = int(t) n = int(n) l = list(map(int, input().split())) m = max(l) s = sum(l) l.sort() j = 1 c = 0 for i in l: if i >= j: j += 1 c += 1 c += m - j + 1 print(s - c)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() c = 0 d = 0 s = sum(a) for i in range(n): c += 1 if a[i] > d: d += 1 c += a[n - 1] - d print(s - c)
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 ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) l = list(map(int, input().split())) l.sort() t = 1 ans = 0 for i in range(n - 1): if l[i] >= t and t < l[n - 1]: t += 1 ans += l[i] - 1 ans += l[n - 1] - (l[n - 1] - t + 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = list(map(int, input().split())) a = list(map(int, input().split())) if n == 1: print(0) exit(0) k = 0 for i in a: if i > 0: k += 1 a.sort() a = a[::-1] c = max(a) d = 0 for i in a: if c > i: c = i if c <= 1: break d += 1 c -= 1 ans = sum(a) - (max(a) + k - 1) + d if d == n and min(a) > 1: ans -= 1 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) ans = 0 need = max(a) for col in a: if col == 1 and need == 1: ans += 1 else: ans += max(1, need - col + 1) need = max(1, min(need - 1, col - 1)) if need != 1: ans += need print(sum(a) - 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
import sys readints = lambda: map(int, input().strip("\n").split()) n, m = readints() a = list(readints()) a = list(reversed(sorted(a))) if n == 1: print(0) sys.exit(0) ans = sum(a) need = a[0] for x in a: if x > need: ans -= 1 need -= 1 elif x == need: ans -= 1 need -= 1 elif x < need: ans -= 1 ans -= need - x need = x - 1 ans -= max(0, need) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.append(0) a.sort() mx = a[n] ans = 0 for i in range(n, 0, -1): cnt = max(1, mx - a[i - 1]) ans += a[i] - cnt mx -= cnt 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 NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = list(map(int, input().rstrip().split())) data = list(map(int, input().rstrip().split())) def mergesort(l): if len(l) == 1: return l llower = [] lupper = [] for i in range(0, int(len(l) / 2)): llower.append(l[i]) for i in range(int(len(l) / 2), len(l)): lupper.append(l[i]) slower = mergesort(llower) supper = mergesort(lupper) b = 0 u = 0 sort = [] while b < len(slower) and u < len(supper): if slower[b] <= supper[u]: sort.append(slower[b]) b = b + 1 elif supper[u] < slower[b]: sort.append(supper[u]) u = u + 1 if b == len(slower): for i in range(u, len(supper)): sort.append(supper[i]) elif u == len(supper): for i in range(b, len(slower)): sort.append(slower[i]) return sort sort = mergesort(data) height = sort[n - 1] total = 0 for i in range(0, n - 1): if sort[n - i - 1] == sort[n - i - 2]: height += -1 total = total + 1 elif height > sort[n - i - 2]: total = total + height - sort[n - i - 2] height = sort[n - i - 2] else: height = height - 1 total = total + 1 total = total + max(1, height) print(sum(data) - total)
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 FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) l = list(map(int, input().split())) if n == 1 or m == 1: print(0) else: ans = sum(l) l.sort(reverse=True) for i in range(n - 1): if l[i] <= l[i + 1]: l[i + 1] = l[i] - 1 l.append(0) for i in range(n): ans -= max(1, l[i] - l[i + 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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = sorted([int(x) for x in input().split()]) total = 0 m = max(a) for i in range(n): if a[i] > total: total += 1 print(sum(a) - n - m + total)
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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() mx = a[-1] t = 0 ans = 0 for i in a: if i > 0: if i > t: t += 1 ans += i - 1 ans -= mx - t 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
def solve(): N, M = map(int, input().split()) A = [int(k) for k in input().split()] A.sort() height = 0 for i in range(1, N + 1): if A[i - 1] > height: height += 1 res = N + (A[-1] - height) print(sum(A) - res) solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = sorted(map(int, input().split())) ans = 0 cur = 0 for b in a: if b > cur: ans += 1 cur += 1 else: ans += 1 print(sum(a) - (ans + max(a) - cur))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() a = a[::-1] sum = int(0) mx = int(0) for i in range(n): sum += a[i] mx = max(mx, a[i]) kol = int(0) for i in range(n): if i != n - 1: a[i + 1] = min(a[i + 1], a[i]) if a[i] == a[i + 1] and a[i] != 1: mx -= 1 kol += 1 a[i + 1] = min(a[i + 1], mx) if a[i] == 1: kol += 1 elif mx > 1 and mx > a[i + 1]: kol += mx - a[i + 1] mx -= mx - a[i + 1] else: kol += a[i] ans = sum - kol 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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) a.append(0) j, s = a[0], 0 for i in range(n): if j > 0: if j - 1 <= a[i + 1] and j - 1 > 0: j -= 1 s += 1 elif j - 1 > a[i + 1]: s += j - a[i + 1] j = a[i + 1] elif a[i + 1] > 0: j = 1 s += 1 elif a[i + 1] == 0: j = 0 s += 1 break else: break print(sum(a) - s)
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = [int(x) for x in input().split()] a.sort() c = 0 maxi = 0 for i in range(n): if maxi + 1 > a[i]: c += a[i] - 1 pass else: maxi += 1 c += a[i] - 1 print(c - a[-1] + maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
input1 = [int(x) for x in input().split()] n = input1[0] m = input1[1] _arr = [int(x) for x in input().split()] arr = sorted(_arr) result = 0 height = 0 for i in range(n - 1): if arr[i] > height: height += 1 result += 1 if arr[-1] == height: result += 1 else: result += arr[-1] - height print(sum(arr) - result)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
s = input() s = s.split() for j in range(len(s)): s[j] = int(s[j]) n = s[0] m = s[1] s1 = input() s1 = s1.split() for j in range(n): s1[j] = int(s1[j]) s1.sort() s1.reverse() pointer = s1[0] res = 0 flag = 0 if n == 1: print(0) else: for i in range(n - 1): if s1[i] != 1: if flag == 1: res = res + s1[i] - 1 elif s1[i] == s1[i + 1]: pointer = pointer - 1 if pointer == 0: flag = 1 pointer = s1[i + 1] res = res + s1[i] - 1 elif pointer - s1[i + 1] > 1: res = res + (s1[i] - pointer) + s1[i + 1] pointer = s1[i + 1] else: pointer = pointer - 1 res = res + s1[i] - 1 if flag == 0: if s1[n - 1] != 1: res = res + s1[n - 1] - pointer if flag == 1: res = res + s1[n - 1] - 1 print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
import sys input_file = sys.stdin [n, m] = list(int(x) for x in input_file.readline().split()) stacks = list(int(x) for x in input_file.readline().split()) stacks.sort() ans = 0 cur_stack = 0 cur_h = 0 while cur_stack < n: ans += 1 if stacks[cur_stack] >= cur_h + 1: cur_h += 1 cur_stack += 1 ans += stacks[-1] - cur_h print(sum(stacks) - ans)
IMPORT ASSIGN VAR VAR ASSIGN LIST VAR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.append(0) a.sort(reverse=True) all_s = sum(a) s = 0 for i in range(1, len(a)): if a[i - 1] > a[i]: s += a[i - 1] - a[i] elif a[i - 1] == a[i]: s += 1 a[i] -= 1 else: s += 1 a[i] = a[i - 1] - 1 print(all_s - s)
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() res = 0 same = 0 p = 1 for h in a: if p <= h: p += 1 else: same += 1 res = a[-1] + same print(sum(a) - 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = input().split() a = [int(i) for i in input().split()] a.sort() c = 0 ans = cc = 0 for i in range(int(n)): if cc > 1: ans += cc - 1 cc += -1 + a[i] - c ans += a[i] - cc else: cc = max(1, a[i] - c) ans += a[i] - cc c = a[i] print(ans)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) l = list(map(int, input().split())) l.sort() c = max(l) low = 0 ans = 0 for i in range(n - 1): if l[i] > low: ans += l[i] - 1 low += 1 else: ans += l[i] - 1 if low == c: ans += low - 1 else: ans += low 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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) l = list(map(int, input().split())) l.sort() res = 0 pre = l[0] - 1 for i in range(len(l) - 1): if l[i] < l[i + 1]: res += l[i] pre += l[i + 1] - l[i] - 1 else: res += l[i] - 1 if pre > 0: pre -= 1 res += 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
line1 = input().split() row, col = int(line1[0]), int(line1[1]) blocks = [int(x) for x in input().split()] def count_removable(blocks): rows = len(blocks) cols = max(blocks) blocks.sort() can_replace = 1 for i in range(1, len(blocks)): block = blocks[i] if block > can_replace: can_replace += 1 keep = rows + cols - can_replace return sum(blocks) - keep print(count_removable(blocks))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() temp = 1 top = 0 side = 0 total = sum(a) for i in range(n): if i == 0: top += 1 side += 1 total -= 1 elif a[i] == temp: top += 1 total -= 1 elif a[i] > temp: side += 1 top += 1 temp += 1 total -= 1 if side < a[n - 1]: total -= a[n - 1] - side if n == 1: print(0) else: print(total)
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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) A = list(map(int, input().split())) s = sum(A) if n == 1: print(0) else: ans = 0 A.sort(reverse=True) for i in range(n - 1): A[i] = min(A[i], m) if A[i] > A[i + 1]: ans += A[i] - A[i + 1] m = min(m, A[i + 1]) else: ans += 1 m = max(1, min(m, A[i] - 1)) ans += m print(s - 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 VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) inp = list(map(int, input().split())) inp.sort() pos = 1 for i in inp[0 : n - 1]: if pos == inp[n - 1]: break elif i >= pos: pos += 1 print(sum(inp) - (n - 1) - (inp[n - 1] - pos + 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 FOR VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) A = sorted(map(int, input().split())) cnt = 0 prev = 0 for a in A: cnt += 1 if a > prev: prev += 1 cnt += A[-1] - prev print(sum(A) - cnt)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
def main(): n, m = map(int, input().split()) a = list(reversed(sorted(map(int, input().split())))) res = 0 h = a[0] b = [] for x in a: if x > h: res += x - h h = min(h, x) b.append(h) if h > 1: h -= 1 for i in range(len(b) - 1): if b[i] > b[i + 1]: res += b[i + 1] print(res) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
ar1 = str(input()).split(" ") ar2 = sorted(str(input()).split(" ")) ar3 = [] for el in ar2: ar3.append(int(el)) ar4 = sorted(ar3) n = int(ar1[0]) m = int(ar1[1]) summ1 = 0 for i in range(len(ar2)): summ1 = summ1 + int(ar2[i]) summ = 0 num = 0 j = 1 for i in range(len(ar4)): if j > int(ar4[i]): num += 1 j -= 1 j += 1 if num > 0: print(summ1 - num - int(ar4[len(ar4) - 1])) else: print(summ1 - ar4[len(ar4) - 1])
ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
N, _ = map(int, input().split()) A = list(map(int, input().split())) A.sort() keep = max(A) up_to = 0 for i in range(N): if A[i] > up_to: up_to += 1 else: keep += 1 print(sum(A) - keep)
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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
R = lambda: map(int, input().rstrip().split()) n, m = R() a = list(sorted(R())) x = 0 prev = 0 for i in range(1, n + 1): x += 1 if a[i - 1] > prev: prev += 1 x += a[n - 1] - prev print(sum(a) - x)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort(reverse=True) m = a[0] ct = 0 for i in range(n): if m == 0: ct += n - i break ct += 1 if a[i] < m: ct += m - a[i] m = a[i] m -= 1 print(sum(a) - (m + ct))
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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() sum1 = sum(a) delete = n possible_height = 0 max_height = a[n - 1] for i in range(n): if a[i] > possible_height: possible_height += 1 print(sum1 - delete + possible_height - max_height)
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 VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() l, p, k = a[n - 1], 0, 0 for i in range(n - 1): if p < l: if a[i] > p: k += a[i] - 1 p += 1 else: k += a[i] - 1 else: k += a[i] - 1 if p >= l: print(k + (a[n - 1] - 1)) else: print(k + (a[n - 1] - (l - p)))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = [int(x) for x in input().split()] a.sort() j = 1 for i in a: if i >= j: j += 1 print(max(sum(a) - n - max(max(a) - j + 1, 0), 0))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
import sys def solve(io): N = io.read_int() M = io.read_int() A = io.read_int_array(N) A = list(sorted(A)) H = max(A) S = sum(A) want = 1 rem = 0 for v in A: if want <= v: want += 1 keep = H + N - (want - 1) rem = S - keep io.println(rem) class IO: in_stream = None out_stream = None raw = "" buf = [] pos = 0 def __init__(self, input_stream, output_stream): self.in_stream = input_stream self.out_stream = output_stream def read_to_buffer(self): self.raw = self.in_stream.readline().rstrip("\n") self.buf = self.raw.split() self.pos = 0 def read_string(self): while self.pos == len(self.buf): self.read_to_buffer() ans = self.buf[self.pos] self.pos += 1 return ans def read_int(self): return int(self.read_string()) def read_float(self): return float(self.read_string()) def read_string_array(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.read_string()) return arr def read_int_array(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.read_int()) return arr def read_float_array(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.read_float()) return arr def read_line(self): while self.pos == len(self.buf): self.read_to_buffer() if self.pos > 0: raise ValueError("Cannot call read_line in the middle of a line.") return self.raw def print(self, s): self.out_stream.write(str(s)) def println(self, s): self.print(s) self.print("\n") def println_array(self, arr, sep=" "): self.println(sep.join(str(x) for x in arr)) def flush_output(self): self.out_stream.flush() pythonIO = IO(sys.stdin, sys.stdout) solve(pythonIO) pythonIO.flush_output()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR CLASS_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER FUNC_CALL VAR STRING RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
from sys import stdin def myfunction(arr, n): my_sum = 0 my_min = 0 if n == 1: return 0 for i in range(n - 1): if arr[i] > my_min: my_min += 1 my_sum += arr[i] - 1 if arr[-1] == my_min: my_sum += arr[i] - 1 else: my_sum += my_min return my_sum n, m = list(map(int, stdin.readline().split())) arr = list(map(int, stdin.readline().split())) arr.sort() print(myfunction(arr, n))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR 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 EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) num = [int(i) for i in input().split()] num.sort() ans = n + num[-1] c = 0 for i in num: if c < i: c += 1 print(sum(num) - ans + c)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
[n, m] = [int(i) for i in input().split()] a = sorted([int(i) for i in input().split()]) a = [i for i in a if i > 0] needLeft = 1 j = 1 for i in range(n): if i == n - 1: needLeft += a[i] - j elif a[i + 1] > j: j += 1 needLeft += 1 else: needLeft += 1 canDelete = sum(a) - needLeft print(canDelete)
ASSIGN LIST 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 VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
R = lambda: map(int, input().split()) n, m = R() i = 0 a = sorted(R()) for x in a: i = min(x, i + 1) print(sum(a) - n - a[-1] + i)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) arr = [int(x) for x in input().split()] tot = sum(arr) ma = max(arr) arr.sort() for i in range(n): if arr[i] == 0: del arr[i] l = len(arr) if True: h = 0 left = 0 for i in range(l - 1): if arr[i] > h: h += 1 left += 1 if h == ma: left += 1 left += ma - h print(tot - left)
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 ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
nos = list(map(int, input().split())) n = nos[0] data = list(map(int, input().split())) suma = 0 for a in range(0, n): suma += data[a] data.sort() data.reverse() ans = 0 data.append(0) for i in range(0, n): if data[i] - data[i + 1] > 0: ans += data[i] - data[i + 1] else: ans += 1 data[i + 1] = data[i] - 1 if data[i + 1] is 0: data[i + 1] = 1 print(suma - ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
class IO: def get(reader=str): return reader(input().strip()) def gets(reader=str, delim=None): return [reader(x) for x in input().strip().split(delim)] def tostr(raw, writer=str, delim=" "): return delim.join(writer(x) for x in raw) n, m = IO.gets(int) a = IO.gets(int) a.sort() pos = 0 for roof in a: pos = min(pos + 1, roof) need = len(a) + a[-1] - pos ans = sum(a) - need print(ans)
CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR NONE RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_DEF VAR STRING RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
inp = input().split() n = int(inp[0]) m = int(inp[1]) inp = input().split() a = [] for i in inp: a.append(int(i)) res = 0 a.sort(reverse=True) tr = a[0] for i in range(0, len(a) - 1): if tr - 1 > a[i + 1]: res += tr - a[i + 1] tr = a[i + 1] else: res += 1 tr = max(1, tr - 1) res += tr print(sum(a) - res)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
I = input n, m = map(int, I().split()) a = list(map(int, I().split())) a.sort() l = 0 h = a[n - 1] ans = 0 for i in range(n): if l == h: ans += a[i] - 1 elif a[i] < l + 1: if a[i] > 1: ans += a[i] - 1 elif a[i] >= l + 1: if i != n - 1: if a[i] > 1: ans += a[i] - 1 l += 1 elif a[i] > 1: ans += l print(ans)
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 VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = list(map(int, input().split())) ans = sum(a) a.sort() lastlevel = 0 level = 0 got = 0 for i in a: got = max(got, i) level = min(level + 1, got) if i > 0: ans -= 1 lastlevel = level ans -= got - level 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 VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) total = 0 req = 0 ans = 0 prev = 0 for i in a: total += i for i in a: req += 1 if i > prev: prev += 1 req += a[-1] - prev ans = total - req print(ans)
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FOR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface. The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$. There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ Find the maximum number of blocks you can remove such that the views for both the cameras would not change. Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right. -----Output----- Print exactly one integer — the maximum number of blocks that can be removed. -----Examples----- Input 5 6 3 3 3 3 3 Output 10 Input 3 5 1 2 4 Output 3 Input 5 5 2 3 1 4 4 Output 9 Input 1 1000 548 Output 0 Input 3 3 3 1 1 Output 1 -----Note----- The following pictures illustrate the first example and its possible solution. Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
input() A = sorted(list(map(int, input().split()))) keep = max(A) up_to = 0 for a in A: if a > up_to: up_to += 1 else: keep += 1 print(sum(A) - keep)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR