description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | s1 = input()
s2 = input()
L1 = [(c == "0") for c in s1]
L2 = [(c == "0") for c in s2]
ans = 0
for i in range(len(s1) - 1):
if L1[i] and L2[i]:
if L1[i + 1]:
L1[i] = L2[i] = L1[i + 1] = False
ans += 1
elif L2[i + 1]:
L1[i] = L2[i] = L2[i + 1] = False
an... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING VAR VAR ASSIGN VAR VAR STRING VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | data = [list(input().strip()), list(input().strip())]
n = len(data[0])
inf = 10**9
ans = 0
for i in range(n - 1):
a = data[0][i] + data[1][i] + data[0][i + 1] + data[1][i + 1]
if a.count("0") >= 3:
ans += 1
if data[0][i] == "0":
data[0][i] = "X"
if data[1][i] == "0":
... | ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | l1 = list(str(input()))
l2 = list(str(input()))
n = len(l1)
count = 0
for i in range(n - 1):
if l1[i] == "0" and l1[i + 1] == "0":
if l2[i] == "0":
l1[i], l1[i + 1], l2[i] = "X", "X", "X"
count += 1
elif l2[i + 1] == "0":
l1[i], l1[i + 1], l2[i + 1] = "X", "X", "X... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING STRING STR... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | TN = 1
def solution():
s1 = list(input())
s2 = list(input())
ans = 0
for i in range(len(s1)):
if s1[i] == "0" and s2[i] == "0" and i - 1 >= 0 and s2[i - 1] == "0":
s1[i] = "X"
s2[i] = "X"
s2[i - 1] = "X"
ans += 1
elif s1[i] == "0" and s2[... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMB... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | a = list(input())
b = list(input())
n = len(a)
res = 0
for i in range(n - 1):
a1, b1, a2, b2 = a[i], b[i], a[i + 1], b[i + 1]
if a1 == "0" and b1 == "0" and a2 == "0" and b2 == "X":
a[i] = "X"
b[i] = "X"
a[i + 1] = "X"
res += 1
elif a1 == "0" and b1 == "0" and a2 == "X" and b... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR VAR STRING ASS... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | s = [list(input()), list(input())]
ans = 0
l = len(s[0])
i = 0
while i < l - 1:
a = s[0][i], s[0][i + 1], s[1][i], s[1][i + 1]
if a.count("0") == 4:
ans += 1
s[0][i + 1] = "X"
i += 1
elif a.count("0") == 3:
ans += 1
i += 2
else:
i += 1
print(ans) | ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER ASSIGN ... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | a1 = input()
a2 = input()
x = [[0, 0, 0, 0] for _ in range(len(a1))]
for i in range(1, len(a1)):
x[i][3] = max(x[i - 1])
if a1[i - 1] == a2[i - 1] == "0":
if a1[i] == "0":
x[i][0] = x[i - 1][3] + 1
if a2[i] == "0":
x[i][1] = x[i - 1][3] + 1
if a1[i] == a2[i] == "0":
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VA... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | try:
while True:
str1 = input()
str1 = "X" + str1 + "X"
str2 = input()
str2 = "X" + str2 + "X"
cnt = [[str1[i], str2[i]].count("0") for i in range(len(str1))]
ans = 0
for i in range(len(str1) - 2):
if cnt[i] + cnt[i + 1] > 2:
cnt[i ... | WHILE NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR FUNC_CALL LIST VAR VAR VAR VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR ... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | a = list(input())
b = list(input())
n = len(a)
r = 0
for i in range(n - 1):
if a[i] == "0" and b[i] == "0":
if a[i + 1] == "0":
a[i + 1], a[i], b[i] = "x", "x", "x"
r += 1
elif b[i + 1] == "0":
b[i + 1], a[i], b[i] = "x", "x", "x"
r += 1
elif a[i +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR STRING STRING STRING VAR NUMBER IF VAR BIN_OP... |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | def f(ch):
if ch == "0":
return 0
else:
return 1
U = [[f(i) for i in list(input())], [f(i) for i in list(input())]]
i = 0
size = len(U[0])
ans = 0
while i + 1 < size:
if U[0][i] + U[0][i + 1] + U[1][i] + U[1][i + 1] > 1:
i += 1
continue
elif U[0][i] + U[0][i + 1] + U[1]... | FUNC_DEF IF VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | T = int(input())
answers = []
for ii in range(T):
length = int(input())
data = list(map(int, input().split()))
m, n = map(int, input().split())
s1, s2 = 0, 0
for i in range(m, n):
s1 = s1 + data[i - 1]
for i in range(n - 1, m + length - 1):
s2 = s2 + data[i % length]
if s1 > ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | import sys
T = int(input())
for z in range(0, T):
N = int(input())
arr = list(map(int, input().split()))
temp = list(map(int, input().split()))
start = temp[0] - 1
end = temp[1] - 1
counter1 = 1000000000000000000
sum1 = 0
for i in range(start, end):
sum1 = sum1 + arr[i]
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUM... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | t = int(input())
for q in range(0, t):
n = int(input())
str_arr = input().split()
arr = [int(num) for num in str_arr]
st, en = input().split()
st = int(st)
en = int(en)
st = st - 1
en = en - 1
s1 = 0
s2 = 0
tmp = st
j = (tmp + n - 1) % n
k = st
v1 = []
v2 = []... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR ... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | import sys
cases = int(input())
while cases > 0:
cases -= 1
lsize = int(input())
data = list(map(int, input().split()))
[start, end] = list(map(int, input().split()))
start -= 1
end -= 1
pt = start
cw = 0
ccw = 0
mincw = 0
maxcw = 0
maxccw = 0
minccw = 0
cw_max_t... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VA... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | def calcDist(s, R):
n = len(R)
dist1 = [[(0) for _ in range(n)] for _ in range(2)]
i, j = (s + 1) % n, (s - 1) % n
while i != s:
dist1[0][i] = dist1[0][(i - 1) % n] + R[(i - 1) % n]
dist1[1][j] = dist1[1][(j + 1) % n] + R[j]
i = (i + 1) % n
j = (j - 1) % n
dist1[0][s]... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | def main():
testCases = int(input())
for i in range(testCases):
solve()
def solve():
N = int(input())
node = [int(i) for i in input().strip().split(" ")]
start, end = [(int(i) - 1) for i in input().strip().split(" ")]
i = start
path1 = []
while i != end:
path1.append(no... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VA... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | T = int(input())
for i in range(T):
N = int(input())
lst = [int(x) for x in input().strip().split()]
prefix_sum = []
for j in lst:
if len(prefix_sum) > 0:
prefix_sum.append(prefix_sum[-1] + j)
else:
prefix_sum.append(j)
U, V = [(int(x) - 1) for x in input().st... | 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 FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CA... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | t = int(input())
for _ in range(t):
n = int(input())
r = []
r = map(int, input().split())
r = list(r)
s, e = map(int, input().split())
s = s - 1
e = e - 1
tot1 = 100000000
tot2 = 100000000
tot3 = 100000000
tot4 = 100000000
tot5 = 100000000
tot6 = 100000000
x1 = 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASS... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | def path(s, e, l, n):
a = 0
while s != e:
a += l[s]
s += 1
s = s % n
return a
def minpath(s, e, l, n):
l1 = [0] * (n + 1)
a = 0
k = 0
k1, k2 = s, e
while s != e:
a += l[s]
k = min(a, k)
s = (s + 1) % n
l1[s] += k
e, s = k1, k2... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | def getbest(ar):
psum, ssum = list(ar), list(ar)
pref, suff = [0] * len(ar), [0] * len(ar)
pref[0] = min(0, ar[0])
suff[len(ar) - 1] = min(0, ar[len(ar) - 1])
for i in range(1, len(ar)):
psum[i] += psum[i - 1]
pref[i] = min(pref[i - 1], psum[i])
for i, e in reversed(list(enumerat... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
start, end = map(int, input().split())
start -= 1
end -= 1
fr, fl = 0, 0
i = start
while i != end:
fr += arr[i]
i = i + 1
i = end
while i != start:
fl += arr[i]
i ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | T = int(input().strip())
for i in range(T):
N = int(input().strip())
R = list(map(int, input().strip().split(" ")))
[start, end] = map(int, input().strip().split(" "))
end = end - 1
left = start - 1
goleft = 0
goleft_back = 0
end_left_back = 0
start_end_back = 0
while left % N !=... | 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 STRING ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSI... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | import sys
def maxSum(x):
total = 0
mn = 0
ret = 0
for k in x:
total += k
ret = max(ret, total - mn)
mn = min(mn, total)
return ret
def solve(a, b, x):
x0 = x[a:b]
x1 = x[b:] + x[:a]
s0 = sum(x0)
s1 = sum(x1)
q0 = maxSum(x0)
q1 = maxSum(x1)
ret... | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CA... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | t = int(input())
ans = []
for i in range(t):
n = int(input())
a = []
b = []
c = []
x = []
y = []
a.extend(map(int, input().split()))
s, e = map(int, input().split())
s1 = sum(a[s - 1 : e - 1])
s2 = sum(a[0 : s - 1]) + sum(a[e - 1 :])
if s != 1:
b.extend(a[e - 2 : s - ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR AS... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | def maxsum(R):
curmax = 0
cursum = 0
curmin = 0
for v in R:
cursum += v
if cursum < curmin:
curmin = cursum
if cursum - curmin > curmax:
curmax = cursum - curmin
return curmax
def dist(R, x, y, z):
return sum(R[x:y]) + 2 * (sum(R[y:z]) - maxsum(R... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR N... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
u, v = map(int, input().split())
fwd = []
u -= 1
v -= 1
for i in range(u - 1, -1, -1):
fwd.append(a[i])
for i in range(n - 1, v - 1, -1):
fwd.append(a[i])
sumF = 0
for i in range(u,... | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL ... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes to play with graphs a lot. Today he created a graph in the following way. He first lays down N nodes in a circle. The nodes nodes are numbered from 1 to N, in the clockwise order, i.e. the node 2 is followed by 1, 3 is followed b... | for t in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
start, finish = [(int(i) - 1) for i in input().split()]
bestrightsstart = [0]
bestleftsstart = [0]
bestrightsfinish = [0]
bestleftsfinish = [0]
s = 0
best = 0
for i in range(start, finish):
... | 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 BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN ... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, c = map(int, input().split())
A = list(map(int, input().split()))
freq = [0] * n
for i in range(n):
if A[i] == c:
freq[i] += 1
for i in range(1, n):
freq[i] += freq[i - 1]
def F(i, j):
return freq[j] - (freq[i - 1] if i >= 1 else 0)
def kadane(B):
ans = cur = mn = 0
for x in B:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR VAR NUMBER V... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | k = [*map(int, input().split())]
list1 = [*map(int, input().split())]
z = [0] * 500001
o = 0
for i in list1:
z[i] = max(z[i], z[k[1]])
z[i] += 1
o = max(o, z[i] - z[k[1]])
print(o + z[k[1]]) | ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_C... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | import sys
input = sys.stdin.readline
n, c = map(int, input().split())
a = list(map(int, input().split()))
N = 5 * 10**5 + 10
ans = [0] * N
res = 0
for aa in a:
ans[aa] = max(ans[aa], ans[c])
ans[aa] += 1
res = max(res, ans[aa] - ans[c])
print(res + ans[c]) | 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 BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR V... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, c = map(int, input().split())
a = list(map(int, input().split()))
cs = 0
x = a.count(c)
best = [x] * 5000001
curr = [x] * 5000001
rec = [0] * 5000001
for i in range(n):
if a[i] == c:
cs += 1
else:
curr[a[i]] = max(x, curr[a[i]] + rec[a[i]] - cs) + 1
best[a[i]] = max(best[a[i]], curr[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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, val = map(int, input().split())
a = [0] + list(map(int, input().split()))
suma = [(0) for i in range(n + 1)]
mx = 0
target = 0
for i in range(1, n + 1):
suma[i] = suma[i - 1]
mx = max(mx, a[i])
if a[i] == val:
target += 1
suma[i] += 1
ans = 0
pre = [(0) for i in range(mx + 1)]
dp = [0]
fo... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASS... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, c = list(map(int, input().split()))
a = list(map(int, input().split()))
nc = 0
last = {}
preconfs = []
preconfc = []
for i in range(n):
if a[i] == c:
nc += 1
last[c] = i
preconfs.append(i)
else:
if not a[i] in last:
preconfs.append(1)
else:
prec... | 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 DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FU... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | t = list(map(int, input().split()))
n = t[0]
c = t[1]
a = list(map(int, input().split()))
f = []
for i in range(0, 500001):
f.append(0)
l = []
for i in range(0, 500001):
l.append([0])
m = 0
for i in range(n):
l[a[i]].append(f[a[i]] - m)
if a[i] == c:
m += 1
f[a[i]] += 1
l[a[i]].append(f[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CA... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | line = input().split()
n = int(line[0])
c = int(line[1])
line = [int(x) for x in input().split()]
base_ans = 0
for num in line:
if num == c:
base_ans += 1
lut = {}
best_delta = 0
for num in line:
if num == c:
to_delete = []
for key in lut:
lut[key] -= 1
if lut[key... | 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER IF V... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | def maxseg(a):
cur_max = 0
global_max = 0
pre_ = 0
for i, x in enumerate(a):
if x > 0:
cur_max = max(x, cur_max + pre_ + x)
global_max = max(global_max, cur_max)
else:
pre_ = x
return global_max
def push(d, u, i):
if u not in d:
d[u] ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VA... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, c = map(int, input().split())
a = [0]
a.extend([int(i) for i in input().split()])
cntc = [0]
seg = {}
last = {}
for i in range(1, n + 1):
cntc.append(cntc[i - 1] + (1 if a[i] == c else 0))
def getcntc(left, right):
return cntc[right] - cntc[left - 1]
for i in range(1, n + 1):
seg.setdefault(a[i], [])... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER NUMBER... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | length, target = [int(i) for i in input().strip().split()]
array = [1000000000000] + [int(i) for i in input().strip().split()]
num_dict = dict()
up, down, pre, dp = [], [], dict(), [(0) for i in range(length + 1)]
index = 0
ans = 0
for i in range(length + 1):
if array[i] == target:
index += 1
up.app... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR LIST LIST FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, c = map(int, input().split())
ans = [0] * 500001
res = 0
for i in map(int, input().split()):
ans[i] = max(ans[i], ans[c])
ans[i] += 1
res = max(res, ans[i] - ans[c])
print(res + ans[c]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | import sys
line = sys.stdin.readline().strip().split()
n = int(line[0])
c = int(line[1])
a = list(map(int, sys.stdin.readline().strip().split()))
cright = [0] * (n + 1)
maxfreq = [0] * (5 * 10**5 + 1)
for i in range(0, n):
if a[n - 1 - i] == c:
cright[n - 1 - i] = cright[n - i] + 1
else:
cright... | IMPORT ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, c = map(int, input().split(" "))
nums = list(map(int, input().split(" ")))
cPast = 0
countC = 0
for value in nums:
if value == c:
countC += 1
def sawC(groupsList):
for key, groups in groupsList.items():
if groups[-1] < 0:
groups[-1] -= 1
else:
groups += [-1]
... | 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 NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER FUNC_DEF FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR LIST NUMBER RETURN VAR ASSIGN VAR ... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | import sys
input = sys.stdin.readline
n, c = map(int, input().split())
ar = list(map(int, input().split()))
br = []
count = 0
for i in range(n):
if ar[i] == c:
count += 1
br.append(count)
dic = {}
for i in range(n):
if ar[i] != c:
if ar[i] in dic:
dic[ar[i]].append(i)
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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR V... |
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$).
What is the maximum possible number of elements with value $c$... | n, c = list(map(int, input().split()))
cnt = [0] * 500005
ans = 0
for v in map(int, input().split()):
if v == c:
cnt[c] = cnt[c] + 1
else:
if cnt[v] < cnt[c]:
cnt[v] = cnt[c]
cnt[v] += 1
ans = max(ans, cnt[v] - cnt[c])
print(ans + cnt[c]) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | def main():
n, m = list(map(int, input().split()))
cost1 = []
cost2 = []
cost3 = []
for i in range(n):
w, c = list(map(int, input().split()))
if w == 1:
cost1.append(c)
elif w == 2:
cost2.append(c)
else:
cost3.append(c)
cost1 = ... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VA... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | import sys
n, m = list(map(int, input().split()))
w1 = []
w2 = []
w3 = [10**10]
for w, c in (list(map(int, l.split())) for l in sys.stdin):
if w == 1:
w1.append(c)
elif w == 2:
w2.append(c)
else:
w3.append(c)
w1.sort(reverse=True)
w2.sort(reverse=True)
w3.sort(reverse=True)
w3[0] = ... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST BIN_OP NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | n, m = list(map(int, input().split()))
a = [[], [], []]
for i in range(n):
w, c = list(map(int, input().split()))
a[w - 1].append(c)
p = [[0], [0], [0]]
for i in range(3):
a[i].sort(reverse=True)
for x in a[i]:
p[i].append(p[i][-1] + x)
ans = 0
for i in range(min(m // 3, len(a[2])) + 1):
w =... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST LIST NUMBER LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | import sys
from itertools import accumulate
def solve():
n, m = map(int, input().split())
w = [[] for i in range(3)]
for i in range(n):
wi, ci = map(int, sys.stdin.readline().split())
wi -= 1
w[wi].append(ci)
for i in range(3):
w[i].sort(reverse=True)
dp = [0] * (m ... | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUM... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | def f():
n, m = map(int, input().split())
l = list(tuple(map(int, input().split())) for _ in range(n))
l.sort(key=lambda e: (0, 6, 3, 2)[e[0]] * e[1], reverse=True)
last, r = [0] * 4, 0
for i, (w, c) in enumerate(l):
if m < w:
break
m -= w
r += c
last[w] =... | 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 VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR VAR VAR FUNC... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | n, m = map(int, input().split())
a = [[], [], []]
for _ in range(n):
x, y = map(int, input().split())
a[x - 1].append(y)
for i in range(3):
a[i].sort(reverse=True)
a_one_odd = []
a_one_even = []
a_length = [len(a[i]) for i in range(3)]
for i in range(0, a_length[0] - 1, 2):
a_one_even.append(a[0][i] + a... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_C... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | import sys
from itertools import accumulate
n, m = map(int, sys.stdin.buffer.readline().decode("utf-8").split())
items = [[], [], [], []]
for w, c in (map(int, line.decode("utf-8").split()) for line in sys.stdin.buffer):
items[w].append(c)
for i in range(1, 4):
items[i].sort(reverse=True)
n_w1, n_w2 = len(item... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST LIST LIST LIST LIST FOR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER F... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | n, m = map(int, input().split())
d = [[] for i in range(3)]
res_odd = 0
res_even = 0
for i in range(n):
t1, t2 = map(int, input().split())
d[t1 - 1].append(t2)
d[0].sort()
d[2].sort(reverse=True)
c = d[1].copy()
if d[0]:
i = len(d[0]) - 2
while i >= 1:
c.append(d[0][i] + d[0][i - 1])
i -... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASS... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | [n, m] = list(map(int, input().strip().split()))
wc = [[] for _ in range(4)]
for _ in range(n):
w, c = list(map(int, input().strip().split()))
wc[w].append(c)
for i in range(1, 4):
wc[i].sort(reverse=True)
iwc = [[(0) for _ in range(len(wc[i]) + 1)] for i in range(4)]
for i in range(4):
for j in range(l... | ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ... |
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | def souvenier_calc(max_weight, weights, value):
const = len(weights)
ans = [(-1061109567) for x in range(max_weight + 1)]
node = [(x, y) for x, y in zip(weights, value)]
node = sorted(node, key=lambda x: x[1] / x[0], reverse=True)
weights = [x[0] for x in node]
value = [x[1] for x in node]
s... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = lambda: sys.stdin.readline()
for i in range(int(input())):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [0] * (n + 1)
for i in range(1, n + 1):
if i < k:
dp[i] = dp[i - 1] + a[i - 1]
else:
dp[i] = mi... | IMPORT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.buffer.readline
def getMinCost(nItems):
idx = nItems - 1
cost = 0
if idx >= k - 1:
cost += kBatchSum[idx]
idx = (idx + 1) % k - 1
if idx >= 0:
cost += aSum[idx]
return cost
t = int(input())
for _ in range(t):
n, p, k = [int(x) for x in in... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CAL... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = list(sorted(map(int, input().split())))
s = 0
maxx = 0
for i in range(0, k + 1):
cnt = 0
summ = 0
if i != k and summ + s + a[i] <= p:
s += a[i]
summ += s
cnt += i + 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [(0) for i in range(n + 1)]
a.sort()
for i in range(1, n + 1):
dp[i] = dp[i - 1] + a[i - 1]
if i >= k:
dp[i] = min(dp[i], dp[i - k] + a[i - 1])
itr = n
while... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
l = [0] * n
l[0] = arr[0]
for i in range(1, k - 1):
l[i] = l[i - 1] + arr[i]
l[k - 1] = arr[k - 1]
for i in range(k, n):
l[i] = l[i - k] + arr[i]
a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBE... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
dp = [float("inf")] * (n + 1)
dp[0] = 0
ans = 0
for i in range(n):
dp[i + 1] = min(dp[i + 1], dp[i] + arr[i])
if i >= k - 1:
dp[i + 1] = min(dp[i + 1... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for j in range(int(input())):
n, p, k = [int(x) for x in input().split()]
goods = [int(x) for x in input().split()]
goods.sort()
dp = [0] * n
dp[0] = goods[0]
if dp[0] > p:
print(0)
continue
for i in range(1, k - 1):
dp[i] = goods[i] + dp[i - 1]
for i in range(k -... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
t = int(input())
ans = [0] * t
for pi in range(t):
n, p, k = map(int, sys.stdin.readline().split())
a = [0] + sorted(map(int, sys.stdin.readline().split()))
for i in range(1, k):
a[i] += a[i - 1]
for i in range(1, n - k + 1):
a[i + k] += a[i]
for i in range(n + 1):
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for ii in range(t):
n, p, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a = [None] + a
s = [0] * (n + 1)
last_ind = 0
for i in range(1, n + 1):
if i < k:
s[i] = a[i] + s[i - 1]
else:
s[i] = a[i] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSI... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for i in range(int(input())):
n, p, k = map(int, input().split())
l = sorted(map(int, input().split()))
dp = [(0) for j in range(n + 1)]
for j in range(1, n + 1):
if j < k:
dp[j] = dp[j - 1] + l[j - 1]
else:
dp[j] = dp[j - k] + l[j - 1]
for j in range(n + 1):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def solve():
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = 0
ans = 0
for i in range(k):
if i:
s += a[i - 1]
tmp = s
ans_tmp = i
if tmp... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | def main():
t = int(input())
for T in range(t):
n, p, k = [int(i) for i in input().split()]
li = sorted([int(i) for i in input().split()])
price = 0
pre = [0] * (len(li) + 1)
for i in range(len(li)):
if i >= k - 1:
temp = li[i] + pre[i - k + 1]... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CAL... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
h = sorted(list(map(int, input().split())))
g = []
for i in h:
if i <= p:
g.append(i)
if k == len(g):
print(len(g))
continue
if p < 1000000000.0:
r = 0
ass = 0
assi = n %... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF V... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | sas = [1, 2, 3]
t = int(input())
for i in range(t):
n, p, k = map(int, input().split())
mas = list(map(int, input().split()))
mas.sort()
l = 0
r = n
def check(m):
if m % k != 0:
sm = 0
i = m % k + k - 1
while i < m:
sm += mas[i]
... | ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_DEF IF BIN_OP VAR VAR NUMBER ASSI... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | def f(p, k, a):
a = [0] + a
dp = [0] * (len(a) + 1)
a = sorted(a)
for i in range(1, len(a)):
dp[i] = dp[i - 1] + a[i]
if i >= k:
dp[i] = min(dp[i], a[i] + dp[i - k])
ans = 0
for i in range(1, len(a)):
if dp[i] <= p:
ans = i
return ans
for _ i... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIG... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for i in range(t):
s = list(map(int, input().split()))
n = s[0]
p = s[1]
k = s[2]
a = list(map(int, input().split()))
a.sort()
r = [0] * k
s = [0] * k
ps = 0
for i in range(1, k):
ps += a[i - 1]
if s[i] + ps <= p:
r[i] += i
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR AS... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
dp = [0] * n
for i in range(n):
if i >= k - 1:
dp[i] = a[i] + dp[i - k]
if dp[i] <= p:
ans = i + 1
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIG... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | def go():
n, p, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
cost = [0] * (n + 1)
for i in range(1, k):
cost[i] = a[i - 1] + cost[i - 1]
for i in range(k, n + 1):
cost[i] = a[i - 1] + cost[i - k]
while cost[n] > p:
n -= 1
return n
t = in... | FUNC_DEF ASSIGN VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
def debug(*args):
print(*args, file=sys.stderr)
t = int(input())
for _ in range(t):
n, p, k = list(map(int, input().split()))
ai = list(map(int, input().split()))
ai.sort()
ai_accum = len(ai) * [0]
for i in range(len(ai)):
ai_accum[i] = ai_accum[i - 1] + ai[i] if i > 0 els... | IMPORT FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 BIN_OP FUNC_CALL VAR VAR LIST NUMBER FOR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (n + 1)
a.sort()
dp[1] = a[0]
for i in range(1, n):
x = a[i] + dp[i]
if i + 1 >= k:
y = a[i] + dp[i - k + 1]
else:
y = 10**18
c... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BI... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for i in range(t):
ch = input()
L = [int(i) for i in ch.split()]
n = L[0]
p = L[1]
k = L[2]
ch = input()
L = [int(i) for i in ch.split()]
L.sort()
L2 = [0] * n
L2[0] = L[0]
for i in range(1, k - 1):
L2[i] = L2[i - 1] + L[i]
L2[k - 1] = L[k - 1]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUM... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, p, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
for i in range(1, k - 1):
a[i] += a[i - 1]
for i in range(k, n):
a[i] += a[i - k]
ans = -1
for i in range(n):
if a[i] <= p:... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
n, p, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
aSum = [(0) for _ in range(n)]
dp = [(0) for _ in range(n)]
ans = 0
for i in range(n):
dp[i] += a[i]
if... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR N... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | from itertools import accumulate
def solve():
n, price, k = map(int, input().split())
arr = list(map(int, input().split()))
arr[:0] = [0]
arr.sort()
dp = [[0, 0] for i in range(n + 1)]
for i in range(1, n + 1):
if i >= k:
p1 = arr[i]
g1 = k
p2 = dp[i... | FUNC_DEF ASSIGN VAR 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 LIST NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
for _ in range(int(input())):
n, p, k = map(int, input().strip().split())
A = list([int(x) for x in sys.stdin.readline().strip().split()])
A.sort()
dp = [0] * k
dp[0] = 0
r = 0
for i in range(1, k):
dp[i] = A[i - 1] + dp[i - 1]
if dp[i] <= p:
r = i
... | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.readline
for nt in range(int(input())):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if p < a[0]:
print(0)
continue
dp = [[0, 0] for i in range(n + 1)]
dp[0][1] = p
dp[1][0] = 1
dp[1][1] = p - a[0]
for ... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [10**18] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
dp[i] = dp[i - 1] + a[i - 1]
if i - k >= 0:
dp[i] = ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
count = 0
without_offer = 0
for i in range(k):
sum = without_offer
if sum > p:
break
count = i
for j in range(i + k - 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR AS... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for _ in range(t):
n, p, k = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
t = [0] * len(l)
c = [0] * len(l)
for i in range(n):
if i < k:
if i == 0:
if p >= l[i]:
t[i] = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for n in range(int(input())):
_, p, k = map(int, input().split())
c = map(int, input().split())
c = sorted(c)
i = 0
pre = 0
ans = 0
while i < len(c) and i < k and pre <= p:
j = i + k - 1
dis = 0
while j < len(c) and dis + pre + c[j] <= p:
dis += c[j]
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | from sys import stdin, stdout
def find(a, s, c, n, j):
for i in range(j + k - 1, n, k):
if a[i] <= s:
s -= a[i]
c += k
else:
break
return c
t = stdin.readline()
t = int(t)
while t > 0:
n, s, k = [int(i) for i in stdin.readline().split()]
a = [int(i... | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR 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 FU... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for tcase in range(int(input())):
nitems, coins, k = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
if ls[0] > coins:
print(0)
continue
best = 0
cumsum = 0
for offset in range(k):
if offset >= nitems or cumsum > coins:
break
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
t = int(sys.stdin.readline().rstrip())
def main():
for _ in range(t):
n, p, k = map(int, sys.stdin.readline().split())
(*a,) = map(int, sys.stdin.readline().split())
a.sort()
cnt = 0
cost = 0
for i in range(k - 1, n, k):
if cost + a[i] <= p:
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 VAR VAR IF BIN_OP VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.readline
t = int(input())
for tt in range(t):
n, p, k = [int(x) for x in input().strip().split()]
a = sorted([0] + [int(x) for x in input().strip().split()])
account_cumsum = [(0) for _ in range(n + 1)]
count_cumsum = [(0) for _ in range(n + 1)]
for i in range(1, k):
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSI... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
sm = 0
ct = 0
for i in range(k + 1):
if i >= len(a):
break
if sm > p:
break
ct = i
pseudocost = sm
j = i... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
r, re = 0, 0
if p < l[0]:
print(0)
else:
pe = p
g = p
c = 0
for i in range(k - 1, n, k):
if pe >= l[i]:
re += k... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIG... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | T = int(input())
INF = float("inf")
for _ in range(T):
N, P, K = map(int, input().split())
arr = sorted([int(x) for x in input().split()])
dp = [None] * N
if arr[0] > P:
print(0)
continue
else:
dp[0] = P - arr[0]
for i in range(1, N):
a = dp[i - 1]
b = dp[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMB... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | tt = int(input())
for kase in range(tt):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [0] * n
for i in range(n):
if i >= k - 1:
dp[i] = a[i] + (dp[i - k] if i - k >= 0 else 0)
else:
dp[i] = a[i] + (dp[i - 1] if i > 0 el... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP V... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for i in range(t):
n, p, k = list(map(int, input().split(" ")))
goods = sorted(list(map(int, input().split(" "))))
numof_goods = [(0) for i in range(n)]
coins = [(0) for i in range(n)]
coins[0] = p - goods[0]
numof_goods[0] = int(coins[0] >= 0)
for i in range(n):
if ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIG... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
while t:
t -= 1
n, p, k = [int(x) for x in input().split()]
li = [int(x) for x in input().split()]
dp = [0] * (n + 1)
li.sort()
dp[0] = p
for i in range(1, min(k - 1, n) + 1):
if dp[i - 1] - li[i - 1] >= 0 and dp[i - 1] != -1:
dp[i] = dp[i - 1] - li[i - 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
reader = (map(int, line.split()) for line in sys.stdin)
def func(a, n, p, k):
D = [0] * (n + 1)
for i in range(1, k):
D[i] = D[i - 1] + a[i - 1]
for i in range(k, n + 1):
D[i] = D[i - k] + a[i - 1]
for i in range(n, -1, -1):
if D[i] <= p:
return i
(t,)... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = [int(o) for o in input().split()]
p1 = p
taken = [0] * n
a = sorted(a)
dp = [0] * (n + 1)
a.append(0)
lol = 0
for i in range(n):
dp[i] = a[i] + dp[i - 1]
cost = dp[:]
for i in range(k - 1, n):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | def f(x, k):
return x // k * k + (1 if x % k > 0 else 0)
for _ in range(int(input())):
n, p, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = [0] * n
s[0] = a[0]
for i in range(1, k - 1):
s[i] = s[i - 1] + a[i]
for i in range(k - 1, n):
s[i] = m... | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = list(map(int, input().split()))
array = list(map(int, input().split()))
array.sort()
dp = [0]
pre = 0
for i in range(k - 1):
pre += array[i]
dp.append(pre)
for i in range(k - 1, n):
dp.append(array[i] + dp[i - k + 1])
ans = ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL V... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | from itertools import *
from sys import *
def dynamic(a, n, k, p):
dp = []
ans = 0
for i in range(0, n):
if i == 0:
dp.append(a[i])
elif i < k - 1:
dp.append(a[i] + dp[i - 1])
elif i == k - 1:
dp.append(a[i])
else:
dp.append(a... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR AS... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
def ints():
return map(int, sys.stdin.readline().split())
for _ in range(int(input())):
n, p, k = ints()
A = list(sorted(ints()))
dp = [0] * k
r = 0
for i in range(1, n + 1):
imk = i % k
dp[imk] = A[i - 1] + dp[(i - 1) % k] if i < k else A[i - 1] + dp[imk]
... | IMPORT 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 VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | from sys import stdin
def input():
return stdin.readline()[:-1]
def intput():
return int(input())
def sinput():
return input().split()
def intsput():
return map(int, sinput())
t = intput()
for _ in range(t):
n, p, k = intsput()
a = list(intsput())
a.sort()
end = n - 1
start... | FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.