description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
def solve(B, G): if max(B) > min(G): return -1 result = sum(B) * len(G) result += sum(G) - max(B) * len(G) if max(B) != min(G): B.sort() result -= B[-2] result += B[-1] return result N, M = map(int, input().split()) B = list(map(int, input().split())) G = list(map(i...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) Boys = [int(x) for x in input().split()] Girls = [int(x) for x in input().split()] if min(Girls) < max(Boys): print(-1) else: Boys.sort(reverse=True) Girls.sort(reverse=True) Ans = 0 for i in range(n): Ans += Boys[i] * m g = 0 b = 0 bins = 1 w...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_C...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = list(map(int, input().split())) b = list(map(int, input().split())) g = list(map(int, input().split())) y = max(b) r = sum(b) z = m * r flag = 0 if max(b) > min(g): print(-1) else: flag = 1 b.sort() u = 0 v = 0 for i in g: if i > y: u += 1 t = i - y ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL ...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
def read_nums(): return [int(x) for x in input().split()] def main(): n, m = read_nums() boys = sorted(read_nums(), reverse=True) girls = sorted(read_nums(), reverse=True) if min(girls) < max(boys): print(-1) return set_boys = set(boys) cum = 0 index = 0 count = 0 ...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VA...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
def main(): n, m = map(int, input().split()) l = list(map(int, input().split())) k = list(map(int, input().split())) l.sort() s = sum(l) * m e = k[0] cnt = 0 for i in range(m): if k[i] < e: e = k[i] if k[i] > l[n - 1]: s += k[i] - l[n - 1] ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) B = list(map(int, input().split())) G = list(map(int, input().split())) if min(G) < max(B): print(-1) exit(0) cnt = 0 z = max(B) y = 0 f = 1 f2 = 0 for i in B: if i != z or f2: y = max(y, i) else: f2 = 1 for i in G: if i == z: f = 0 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
nBoys, nGirls = map(int, input().split()) boys = sorted(map(int, input().split()), reverse=True) girls = sorted(map(int, input().split())) if boys[0] > girls[0]: print(-1) return ret = sum(girls) for i in range(1, nBoys): ret += boys[i] * nGirls if boys[0] != girls[0]: ret -= girls[0] - boys[0] ret ...
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 NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VA...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
l = input().split(" ") n = int(l[0]) m = int(l[1]) B = input().split(" ") B = [int(x) for x in B] J = input().split(" ") J = [int(x) for x in J] J.sort() B.sort() if J[0] < B[-1]: print(-1) exit() k = n - 1 sm = sum(B) l = (sm - B[-1]) * m s = l for i in J: s += i if B[-1] != J[0]: s = s + B[-1] - B[-2]...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUM...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
import sys input = sys.stdin.readline n, m = map(int, input().split()) b = [int(k) for k in input().split()] g = [int(k) for k in input().split()] if max(b) > min(g): print(-1) elif max(b) == min(g): print(sum(b) * m + sum(g) - max(b) * m) else: b.sort() print(sum(b) * m + sum(g) - max(b) * (m - 1) - b...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().strip().split(" ")) b = list(map(int, input().strip().split(" "))) g = list(map(int, input().strip().split(" "))) b.sort() b = b[::-1] g.sort() g = g[::-1] impossible = False if b[0] > g[-1]: impossible = True result = 0 boy_max = b[0] for girl in g[:-1]: result += girl result += boy_max...
ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUM...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = [int(t) for t in input().split(" ")] b = [int(t) for t in input().split(" ")] g = [int(t) for t in input().split(" ")] count = 0 max_b = max(b) min_sat = False rest_b = sum(b) - max_b for gi in g: count += gi + rest_b min_sat |= gi == max_b if not min_sat: b = sorted(b, reverse=True) count += b[0...
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR VAR VAR BIN...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
import sys num_b, num_g = map(int, input().split(" ")) B = list(map(int, input().split(" "))) G = list(map(int, input().split(" "))) max_b = max(B) min_g = min(G) if max_b > min_g: print(-1) sys.exit(0) max_b = 0 second_max_b = 0 for i, b in enumerate(B): if b >= max_b: second_max_b = max_b ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR F...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) s = sorted(list(map(int, input().split()))) if a[-1] > s[0]: print(-1) elif a[-1] == s[0]: print(sum(a[:-1]) * m + sum(s)) else: print(sum(a[:-2]) * m + a[-2] * (m - 1) + sum(s) + a[-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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) B = list(map(int, input().split())) G = list(map(int, input().split())) B.sort(reverse=True) G.sort(reverse=True) if G[-1] == B[0]: ans = sum(G) for i in range(1, n): ans += m * B[i] elif G[-1] < B[0]: print(-1) exit() else: ans = sum(G[0 : m - 1]) + B[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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR N...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
import sys input = lambda: sys.stdin.readline().strip("\r\n") n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) if a[-1] > b[0]: print(-1) elif a[-1] == b[0]: print(sum(b) + sum(a[:-1]) * m) else: print(sum(b) + a[-1] + sum(a[:-1]) * m ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER I...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = [int(x) for x in input().split()] a = sorted([int(x) for x in input().split()]) b = [int(x) for x in input().split()] if max(a) < min(b): print(sum(a) * m + sum(b) - a[-1] * (m - 1) - a[-2]) elif max(a) == min(b): print(sum(a) * m + sum(b) - a[-1] * m) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_O...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
R = lambda: list(map(int, input().split())) n, m = R() a = R() b = R() a.sort() b.sort() M = a[n - 1] test = 0 s = 0 for j in range(m): if b[j] < M: test = 1 break if test == 1: print(-1) else: k = 0 for i in range(m): if b[i] == a[n - 1]: k = 1 if k == 1: ...
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 ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR N...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
def main(): n, m = map(int, input().split()) b = sorted([int(i) for i in input().split()]) g = sorted([int(i) for i in input().split()]) x, y = b[-1], g[0] if x > y: print(-1) elif x == y: print(sum(b) * m + sum(g) - x * m) else: print(sum(b) * m + sum(g) - x * (m - 1...
FUNC_DEF 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 FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP B...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) b = list(map(int, input().split())) g = list(map(int, input().split())) mx = max(b) mn = min(g) if mn >= mx: b.sort() g.sort() sb = sum(b) sg = sum(g) ans = sb * m if mn == mx: ans = ans - m * mx + sg else: ans = ans - b[n - 1] * (m - 1) + sg ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL V...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
import sys input = sys.stdin.readline n, m = map(int, input().split()) b = list(map(int, input().split())) g = list(map(int, input().split())) b.sort() g.sort() if b[-1] > g[0]: print(-1) exit() if b[-1] == g[0]: ans = 0 for i in range(n - 1): ans += b[i] * m ans += sum(g) print(ans) el...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) b = [] g = [] str = input() b = list(map(int, str.split(" "))) str = input() g = list(map(int, str.split(" "))) b.sort(reverse=True) g.sort(reverse=True) candies = 0 if b[0] > g[m - 1]: print(-1) elif b[0] < g[m - 1]: for i in range(m - 1): candies = candies + g[i] c...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER A...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
R = lambda: map(int, input().split()) n, m = R() a = list(R()) b = list(R()) a.sort() b.sort() t = sum(a) * m + sum(b) - a[-1] * m if a[-1] > b[0]: print(-1) elif a[-1] == b[0]: print(t) else: print(t + a[-1] - a[-2])
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXP...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) boys = list(map(int, input().split())) girls = list(map(int, input().split())) boys = sorted(boys, reverse=True) minA = min(girls) c = 0 if boys[0] > minA: print(-1) else: check = 0 if boys[0] not in girls else 1 c += sum(girls) for i in range(1, n): if not check...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER AS...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) b = sorted(list(map(int, input().split())), reverse=True) g = sorted(list(map(int, input().split())), reverse=True) j = 0 ans = 0 for j in range(m - 1): if b[0] > g[j]: print(-1) exit(0) ans += g[j] if b[0] > g[m - 1]: print(-1) exit(0) elif b[0] == g[m -...
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 NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMB...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
from sys import exit N, M = map(int, input().split()) B = list(map(int, input().split())) G = list(map(int, input().split())) B.sort() mB = B[-1] m2B = B[-2] mG = min(G) if mB > mG: print(-1) exit() if mB == mG: print(sum(B) * M + sum(G) - mB * M) exit() print(sum(B) * M + sum(G) - mB * M + mB - m2B)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) mn = sorted(map(int, input().split()), reverse=True) mx = list(map(int, input().split())) if min(mx) < mn[0]: print(-1) else: r = m * sum(mn[1:]) + sum(mx) if mn[0] not in mx: r += mn[0] - mn[1] print(r)
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 NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL ...
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g...
n, m = map(int, input().split()) b = list(map(int, input().split())) g = list(map(int, input().split())) ind = 0 p = m - 1 ans = sum(b) * m b.sort(reverse=1) g.sort(reverse=1) for i in range(m): if g[i] < b[0]: print(-1) exit() if g[i] > b[0]: if ind == n: print(-1) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL V...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def moze(v, r, n): s = 0 for i in range(n): if r[i] - v < 0: s += (-r[i] + v) // 2 else: s -= r[i] - v if s >= 0: return True return False def nadji(r, n, m): l = (m - 1) // n + 1 right = 2 * l iz = -1 while l <= right: sredina = ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR B...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
T = int(input()) while T: T -= 1 n, m = map(int, input().split()) freq = [0] * n arr = list(map(int, input().split())) for ele in arr: freq[ele - 1] += 1 count = [0] * (m + 1) for fre in freq: count[fre] += 1 for i in range(1, m + 1): count[i] += count[i - 1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR V...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def solve(n: int, m: int, arr): counter = [(0) for _ in range(n + 1)] for val in arr: counter[val] += 1 minimal_time = 0 maximal_time = len(arr) // n * 2 + 5 while maximal_time - minimal_time > 1: time = (maximal_time + minimal_time) // 2 amount_of_task_solved = 0 for...
FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASS...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) cnt = [0] * n for i in list(map(int, input().split())): cnt[i - 1] += 1 lo, hi = 0, max(cnt) while lo < hi: mid = lo + hi >> 1 s = 0 for i in cnt: if i > mid: s += mid ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
t = int(input()) while t: t -= 1 n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] arr = [0] * n for x in a: arr[x - 1] += 1 l = 1 r = max(arr) def can(time): remain = 0 for x in arr: if x >= time: remain +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) nums = list(map(int, input().split())) tmp = [0] * n for num in nums: tmp[num - 1] += 1 l, r = 1, m * 2 while l <= r: m = (l + r) // 2 unperformed_nonproficient_work = 0 res_time = 0 for ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR AS...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = list(map(int, input().split())) arr = list(map(int, input().split())) p = [0] * n for i in arr: p[i - 1] += 1 l = 0 r = 2 * m while l < r: x = (l + r) // 2 done = 0 for i in p: if i <= x: done +=...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
class ScheduleManagement: def __init__(self, n, m, a): self.n = n self.m = m self.a = a self.cnt = [0] * self.n for i in self.a: self.cnt[i - 1] += 1 def isPossible(self, t): work2hr = 0 work1hr = 0 for i in range(self.n): ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUM...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) mp = {i: (0) for i in range(1, n + 1)} a = list(map(int, input().split())) for v in a: mp[v] += 1 def check(time): t_c = 0 for k in mp: if mp[k] > time: t_c += time else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) c = [0] * n nums = map(int, input().split()) for i in nums: c[i - 1] += 1 low = 0 high = max(c) while high - low > 1: mid = (high + low) // 2 if sum(mid if x >= mid else x + (mid - x) // 2 for x in c) >= m...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) d = dict() l = list(map(int, input().split())) for i in range(1, n + 1): d[i] = 0 for i in l: d[i] += 1 mxt = m lo = 1 hi = mxt while lo < hi: mid = (lo + hi) // 2 z = mid * 1 extra...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
t = int(input()) while t > 0: t -= 1 n, m = map(int, input().split()) arr = list(map(int, input().split())) low, high = -1, m + 1 while low < high - 1: mid = (high + low) // 2 freq = [0] * n for x in arr: freq[x - 1] += 1 count = 0 for x in freq: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIS...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
t = int(input()) while t > 0: t -= 1 n, m = list(map(int, input().split())) proficiency = list(map(int, input().split())) lower = 1 upper = 2 * m frequency = {} for i in range(1, n + 1): frequency[i] = 0 for x in proficiency: frequency[x] += 1 ans = 0 while lower ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIG...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
test = int(input()) while test: n, m = map(int, input().split()) a = [int(x) for x in input().split()] low = 1 high = 2 * m work = [0] * (n + 1) for i in a: work[i] += 1 ans = 0 while low <= high: mid = (low + high) // 2 left_task = 0 for i in range(1, n +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASS...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
q = int(input()) for _ in range(q): n, m = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) b = [0] * n for i in range(m): b[a[i]] += 1 l = 0 r = 1000000 while r - l > 1: m = (l + r) // 2 cnt = 0 for i in range(n): if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
tc = int(input()) while tc > 0: A = [int(i) for i in input().split(" ")] B = [int(i) for i in input().split(" ")] n = A[0] m = A[1] w = [(0) for i in range(n)] for i in B: w[i - 1] += 1 ans = 0 while m != 0: w.sort(reverse=True) for i in range(n): if m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN 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 ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) arr = list(map(int, input().split())) d = dict([(i, 0) for i in range(1, n + 1)]) for i in arr: d[i] += 1 l, r = 0, m while l < r: x = (l + r) // 2 t, w = 0, 0 for i in range(1, n + 1): if ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def solve(d): total = sum(d if x > d else x + (d - x) // 2 for x in c) return total >= m for _ in range(int(input())): n, m = map(int, input().split()) c = [0] * n for x in map(int, input().split()): c[x - 1] += 1 low = 0 high = max(c) while high - low > 1: mid = (high ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBE...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def solve(n, m, pros): prof = [(0) for i in range(n)] for _pro in pros: prof[_pro - 1] += 1 for t in range(0, m * 2 + 1): capacity = 0 for w in range(n): prof_completed = min(t, prof[w]) non_prof_completed = 0 if prof_completed < t: ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def b(t): bal = 0 for i in f: if i >= t: bal += i - t else: bal -= (t - i) // 2 return bal <= 0 out = [] for _ in range(int(input())): n, m = map(int, input().split()) a = [int(i) for i in input().split()] f = [0] * n for i in a: f[i - 1] += ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LI...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
MOD = 10**9 + 7 fac_mem = [1] def fac(n): while len(fac_mem) < n + 1: fac_mem.append(fac_mem[-1] * len(fac_mem) % MOD) return fac_mem[n] def perm(n, k): return fac(n) * pow(fac(k), MOD - 2, MOD) % MOD def comb(n, k): return fac(n) * pow(fac(k) * fac(n - k) % MOD, MOD - 2, MOD) % MOD clas...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETU...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
t = int(input()) for i in range(t): n, m = map(int, input().split()) a = list(map(int, input().split())) dela = [0] * n for x in a: dela[x - 1] += 1 dela.sort() skol = [0] * (dela[-1] + 1) s = 0 kol = n for x in range(len(dela)): if dela[x] != s: skol[s] =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
t = int(input()) while t: s = input().split() n, m = map(int, s) s = input().split() a = list(map(lambda x: int(x) - 1, s)) cnt = {i: (0) for i in range(n)} for i in a: cnt[i] += 1 def isvalid(x): extra = 0 helpn = 0 for i in range(n): if x > cnt[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VA...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
t = int(input()) while t: n, m = list(map(int, input().split())) lst = list(map(int, input().split())) a = [(0) for i in range(n + 1)] for k in lst: a[k] += 1 up = 2 * m low = 0 ans = 2 * m while low <= up: mid = low + (up - low) // 2 work = 0 time = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIG...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def max_tasks_in_time(t): can_complete = 0 for w in range(n): tasks_as_profi = min(prof[w], t) can_complete += tasks_as_profi + (t - tasks_as_profi) // 2 return can_complete tests = int(input()) ans = [] for _ in range(tests): n, m = map(int, input().split(" ")) task_profi = input(...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def helper(p, t, n): rem = 0 for i in range(n): if p[i] > t: rem = rem + (p[i] - t) else: v = (t - p[i]) // 2 rem = rem - v return rem <= 0 for i in range(int(input())): n, m = map(int, input().split()) arr = list(map(int, input().split())) p...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for h in range(int(input())): n, m = map(int, input().split()) x = list(map(int, input().split())) vec = [0] * n for i in x: vec[i - 1] += 1 vec.sort(reverse=True) l, r = 0, m * 2 v = m * 2 while l <= r: m = (l + r) // 2 ct = 0 for i in vec: if...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIG...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) l = list(map(int, input().split())) d = [0] * n for i in l: d[i - 1] += 1 t = sorted(d) ans = max(t) i = 0 j = t[-1] while i <= j: md = (i + j) // 2 a = 0 b = 0 for x in t: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NU...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def check(time): total = 0 for i in range(1, n + 1): if workers[i] >= time: total -= workers[i] - time else: total += (time - workers[i]) // 2 if total >= 0: return True else: return False def search(left, right): while left <= right: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR IF...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
a = [] n, m = 0, 0 def bis(lef, rig): if rig - lef == 1: return rig time = [0] * n mid = lef + (rig - lef) // 2 surp = 0 for i in a: if time[i - 1] < mid: time[i - 1] += 1 else: surp += 1 for i in time: surp -= (mid - i) // 2 if surp ...
ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER I...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) b = [(0) for i in range(1, n + 1, 1)] for i in range(m): b[a[i] - 1] += 1 t = max(b) l = 0 while t - l > 1: mid = (l + t) // 2 if sum(mid if x > mid else x + (mid - x) /...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CAL...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
T = int(input()) for t in range(0, T): n, m = map(int, input().split()) a = list(map(int, input().split())) hm = [(0) for i in range(0, n)] for item in a: hm[item - 1] += 1 l = 0 r = m while l <= r: need_help = 0 give_help = 0 mid = (l + r) // 2 for i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHI...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
for _ in range(int(input())): n, m = map(int, input().split()) l = [0] * n for i in list(map(int, input().split())): l[i - 1] += 1 cur = 0 time = 0 while m > 0: time += 1 num = 0 for i in range(n): if l[i] != 0 and num < m: l[i] -= 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR ...
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $1$ hour. Otherwise, it takes them $2$ hours. ...
def get_sum_strength(tasks, hours): s_sum = 0 for task in tasks: s_sum += min(task, hours) + int(0.5 * max(hours - task, 0)) return s_sum for _ in range(int(input())): n, m = list(map(int, input().split())) a = list(map(lambda x: int(x) - 1, input().split())) tasks = [0] * n for ta...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_C...
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i an...
def possible(b, g): if min(g) > max(b): return False return True def is_valid(b, g): max(b) >= min(g) n, m = [int(x) for x in input().split()] b = [int(x) for x in input().split()] g = [int(x) for x in input().split()] B = sum(b) ans = B * m mx = max(b) if max(b) > min(g): ans = -1 elif min(...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CAL...
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i an...
n, m = [int(x) for x in input().split()] pir = [int(x) for x in input().split()] ant = [int(x) for x in input().split()] ats = sum(pir) * m did = max(pir) antmaz = min(ant) if antmaz < did: print(-1) exit() pir.sort(reverse=True) ant.sort() for i in range(1, m): ats += ant[i] - did if ant[0] != did: ats...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def gift(): for _ in range(t): n = int(input()) b = list(map(int, input().split())) b.append(2 * n + 1) rem = [] nex = 1 for i in b: while nex != i: rem.append(n...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR EXPR FUNC_CAL...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) for _ in range(t): n = int(input()) b = list(map(int, input().split())) max_force = 0 min_force = 0 legacy = 0 possibility = 0 for i in b: jump = i - legacy - 1 possibility += jump if possibility > 0: possibility -= 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
n = int(input()) for _ in range(n): m = int(input()) lst = list(map(int, input().split())) used = 0 smallest = m for num in lst: if num - 1 > used: smallest -= 1 used += 2 else: used += 1 used = 0 greatest = 0 for num in lst[::-1]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VA...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys input = sys.stdin.readline def solve(): n = int(input()) arr = list(map(int, input().split())) S = set(arr) exc = cnt1 = 0 for i in range(1, 2 * n + 1): if i not in S: exc += 1 continue if exc: cnt1 += 1 exc -= 1 f = n...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VA...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys input = sys.stdin.buffer.readline t = int(input()) for _ in range(t): n = int(input()) b = [int(x) for x in input().split()] b.sort() a = [] j = 0 for i in range(1, n * 2 + 1): if j < n and i == b[j]: j += 1 else: a.append(i) maxX = 0 i...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR ...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
def find_forward(n, b): total = h = bank = 0 z = 1 while z <= 2 * n: if h != n and z == b[h]: if bank: bank -= 1 else: total += 1 h += 1 else: bank += 1 z += 1 return total def find_backward(n, b): ...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR IF VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER ...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
def solve(): n = int(input()) b = list(map(int, input().split())) cnt = 0 cur = 0 mx = 0 for i in range(n): cnt += b[i] - cur - 1 cur = b[i] if cnt > 0: cnt -= 1 mx += 1 cnt = 0 cur = 2 * n + 1 mn = 0 for i in range(n - 1, -1, -1): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
from sys import stdin q = int(input()) for j in range(q): n = int(input()) b = list(map(int, input().split())) used = [0] * 2 * n for i in range(n): used[b[i] - 1] = 1 free = 0 ma = 0 for i in range(n * 2): if used[i]: if free > 0: ma += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
from sys import stdin t = int(stdin.readline()) for case in range(t): n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] need = set(a) missing = [] for x in range(1, n * 2 + 1): if not x in need: missing.append(x) reverse = missing[::-1] maxD = floa...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMB...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
(T,) = map(int, input().split()) for _ in range(T): (N,) = map(int, input().split()) X = list(map(int, input().split())) Y = [0] * (2 * N + 1) for x in X: Y[x] = 1 u, v = 0, 0 r = 0 rr = 0 for i in range(1, 2 * N + 1): if Y[i]: u += 1 if u > v: ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUM...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) for g in range(t): n = int(input()) b = list(map(int, input().split())) a = [] j = 0 for i in range(1, 2 * n + 1): if j < n and i == b[j]: j += 1 else: a.append(i) i = 0 j = 0 l = 0 while i < n and j < n: if a[i] < b[j]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR V...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
from sys import stdin, stdout def pairs(n, b_a): x_a = [] b_s = set(b_a) for i in range(1, 2 * n + 1): if i not in b_s: x_a.append(i) idx = 0 x = 0 for b in b_a: while idx < n and x_a[idx] < b: idx += 1 if idx >= n: break x +=...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VA...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
from sys import stdin T = int(stdin.readline().strip()) for caso in range(T): n = int(stdin.readline().strip()) s = list(map(int, stdin.readline().strip().split())) s.sort() ind = 0 acum = 0 xmin = 0 for i in range(1, 2 * n + 1): if s[ind] == i: if acum == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUM...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for _ in range(int(input())): n = int(input()) (*b,) = map(int, input().split()) b.sort() lres = 0 rres = 0 can_be_max = [-1] * n can_be_min = [-1] * n for i in range(n): if b[i] < 2 * i + 2 - lres: can_be_max[i] = 0 lres += 1 else: can...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP BIN_...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) for _ in range(t): n = int(input()) come_out = list(map(int, input().split())) stay_in = [] i = 0 for j in range(1, 2 * n + 1): while i < n and come_out[i] < j: i += 1 if i == n or i < n and come_out[i] > j: stay_in.append(j) j = 0 max...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VA...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) for _ in range(t): n = int(input()) b = list(map(int, input().split())) s = set(b) arr = [1] * (2 * n) pos = 0 mini = 0 for i in range(n): pos = max(pos, b[i]) temp = pos for j in range(pos, 2 * n): if j + 1 not in s and arr[j] == 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for nt in range(int(input())): n = int(input()) a = list(map(int, input().split())) sa = set(a) b = [] for i in range(1, 2 * n + 1): if i not in sa: b.append(i) sb = set(b) arr = [] for i in range(1, 2 * n + 1): if i in sb: arr.append(1) el...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for tt in range(int(input())): n = int(input()) l = list(map(int, input().split())) k = [(1) for i in range(2 * n)] for i in l: k[i - 1] = -1 ans = n + 1 cnt = 0 mi = 0 for i in range(2 * n): cnt += k[i] mi = max(mi, -cnt) ans -= mi cnt = 0 mi = 0 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMB...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for _ in range(int(input())): n = int(input()) arr = [False] * (2 * n) for x in input().split(): arr[int(x) - 1] = True left = 0 available = 0 for x in arr: if x: available += 1 elif available: available -= 1 left += 1 right = 0 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x ...
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NU...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) def check_first_x(x): i = x - 1 j = n - 1 while i >= 0: if arr[i] > left[j]: return False i -= 1 j -= 1 return True def check_last_x(x): i = n - 1 j = x - 1 while j >= 0: if arr[i] < left[j]: return False i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER ...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n = int(input()) B = list(map(int, input().split())) SETB = set(B) MINOK = [0] * n MAXOK = [0] * n minpair = 0 for i in range(n): b = B[i] while minpair <= b or minpair in SETB: minpair...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for _ in range(int(input())): n = int(input()) b = list(map(int, input().split())) used = [0] * (2 * n + 1) for x in b: used[x] = 1 a = [x for x in range(1, 2 * n + 1) if used[x] == 0] max_ = 0 l, r = 0, len(a) - 1 for x in b[::-1]: if x < a[r]: max_ += 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUM...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys def main(): def modst(a, s): ret = 1 while s: if s % 2: ret = ret * a % mod a = a * a % mod s //= 2 return ret def Cnk(n, k): return (k <= n and n >= 0) * ( f[n] * modst(f[k] * f[n - k] % mod, mod - 2)...
IMPORT FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIG...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
def binarySearch(A, B, n): low, high = 0, n while low < high: mid = low + (high - low + 1) // 2 flag = 1 for index in range(mid): if A[index] > B[n + index - mid]: flag = 0 if flag == 0: high = mid - 1 else: low = mid ...
FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) for ti in range(t): (n,) = map(int, input().strip().split(" ")) b = list(map(int, input().strip().split(" "))) a = [] ptr = 0 for i in range(1, n * 2 + 1): if ptr < n and i == b[ptr]: ptr += 1 else: a.append(i) ptr = 0 mmi = 0 for ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN 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 ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) for _ in range(t): n = int(input()) arr = [(0) for i in range(2 * n)] l = list(map(int, input().split())) for i in range(n): arr[l[i] - 1] = 1 arr1 = [] arr2 = [] for i in range(2 * n): if arr[i] == 1: arr1.append(i + 1) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LI...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for t in range(int(input())): n = int(input()) visited = [(False) for i in range(2 * n + 1)] b = list(map(int, input().split())) for i in range(n): visited[b[i]] = True i = 2 * n store, w = 0, n para = 0 while i > 0 and w > 0: if visited[i] == True: w -= 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) b = [0] + list(map(int, input().split())) + [2 * n + 1] bb = [] interval = [] for i in range(n + 1): interval.append(b[i + 1] - b[i] - 1) min_x = 0 rem = 0 for e in interval[n - 1 :: -1]: ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FU...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for _ in range(int(input())): n = int(input()) b = [int(x) for x in input().split()] j, count = 0, 0 bad_left, bad_right = 0, 0 for i in range(1, 2 * n + 1): if j < n and b[j] == i: j += 1 if count == 0: bad_left += 1 else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUM...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for _ in range(int(input())): n = int(input()) a = [-1] * (2 * n) arr = [int(x) for x in input().split()] for x in arr: a[x - 1] = 1 mx = -float("inf") mn = -mx t = 0 for i in range(2 * n): t += a[i] mx = max(mx, t) t = 0 for i in range(2 * n - 1, -1, -1):...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for z in range(int(input())): n = int(input()) a = [1] * (2 * n) for i in map(int, input().split()): a[i - 1] = -1 x = 0 s = 0 for i in a: if i < 0: if s > 0: x += 1 s -= 1 else: s += 1 x = n - x y = 0 s ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
t = int(input()) while t: t -= 1 n = int(input()) b = list(map(int, input().split())) cnt = 0 last = 0 nans = 0 for i in b: cnt += i - last - 1 if cnt > 0: nans += 1 cnt -= 1 last = i b.reverse() xans = 0 cnt = 0 last = 2 * n + ...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
from sys import stdin, stdout input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) arr = [int(x) for x in input().split()] arr = sorted(arr) val = arr[0] s = set(arr) q = [i for i in range(1, 2 * n + 1)] m = 0 counter = 0 for i in arr: while 1: ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) mark = [0] * (2 * n + 1) b = [int(x) for x in input().split()] for x in b: mark[x] = 1 a = [] for x in range(1, 2 * n + 1): if mark[x] == 0: a.append(x) lo, hi = 0, n while l...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for ct in range(int(input())): n = int(input()) b = list(map(int, input().split())) x = y = 0 for i, v in enumerate(b): x = max(x, 2 * (i + 1) - v) y = max(y, v - 2 * (i + 1) + 1) print(n - x - y + 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_...
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements. Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of...
for _ in range(int(input())): n = int(input()) t = list(map(int, input().split(" "))) a = 1 y = [] for i in range(n + 1): for a in range(a, t[i % n] if n - i > 0 else n * 2 + 1): y.append(a) a = t[i % n] + 1 if n - i > 0 else t[i - 1] + 1 k = 0 ans2 = 0 ans1 =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP VA...