description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = e = ans = c = ans_s = 0
ans_e = -1
while e < n:
if not a[e]:
c += 1
while c > k and e >= s:
if not a[s]:
c -= 1
s += 1
if c <= k and e - s + 1 > ans_e - ans_s + 1:
ans_s = s
ans_e = e
e += 1
print(ans_e - ans_s + 1)
for i in range(n):
if i >= ans_s and i <= ans_e:
print(1, end=" ")
else:
print(a[i], end=" ")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
s = input().split()
n, k = int(s[0]), int(s[1])
s = input().split()
a = []
for x in s:
a.append(int(x))
L, R = [], []
for i in range(n + 2):
L.append(0)
R.append(0)
for i in range(1, n + 1):
if a[i - 1] == 1:
L[i] = L[i - 1] + 1
for i in range(n, 0, -1):
if a[i - 1] == 1:
R[i] = R[i + 1] + 1
zeros = []
for i in range(n + 2):
zeros.append(0)
c = 0
for i in range(1, n + 1):
c += a[i - 1] == 0
zeros[i] = c
z = 0
l, r = 0, k + 1
left, right = -1, -1
while l <= r and r <= n + 1:
t = zeros[r - 1] - zeros[l]
if t > k:
l += 1
else:
x = L[l] + R[r] + (r - l - 1)
if x > z:
z = x
left, right = l + 1, r - 1
r += 1
print(z)
for i in range(n):
if i + 1 >= left and i + 1 <= right:
print("1", end=" ")
else:
print(a[i], end=" ")
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR STRING
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
i = 0
j = 0
c = 0
an = 0
p = [0, n - 1]
while j < n and c < k:
if a[j] == 0:
c += 1
j += 1
an = j - i
p = [i, j]
while j < n:
if a[j] == 0:
while a[i] != 0:
i += 1
i += 1
j += 1
if j - i > an:
an = j - i
p = [i, j]
print(an)
print(*(a[: p[0]] + ["1"] * an + a[p[1] :]))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR WHILE VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP LIST STRING VAR VAR VAR NUMBER
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
b = {(-1): 0}
c, l, r, st, ed = 0, 0, 0, 0, 0
for i in range(n + 1):
if a[i] == 0:
c += 1
b[i] = c
while l <= n and r <= n:
k1 = b[r] - b[l - 1]
if k1 <= k:
r += 1
else:
if r - l >= ed - st:
st, ed = l, r
l += 1
r -= 1
if st == ed == 0:
ed = n
for i in range(st, ed):
a[i] = 1
print(ed - st)
a.pop(-1)
print(*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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
a, b = map(int, input().split())
z = list(map(int, input().split()))
ans = []
for i in range(len(z)):
if z[i] == 0:
ans.append(i)
freq = []
count = 1
inde = 0
if len(ans) == 0:
print(len(z))
print(*z)
exit()
pair = [[0, 0] for i in range(len(ans))]
if z[0] == 0:
inde = 1
for i in range(1, len(z)):
if z[i] == z[i - 1]:
count += 1
if z[i] == 0:
inde += 1
else:
freq.append(count)
if z[i] == 0:
pair[inde][0] = count
inde += 1
count = 1
freq.append(count)
if b == 0:
if z[0] == 1:
print(max(freq[0::2]))
print(*z)
else:
if len(freq) == 1:
print(0)
print(*z)
exit()
print(max(freq[1::2]))
print(*z)
exit()
for i in range(1, len(ans)):
pair[i - 1][1] = ans[i] - ans[i - 1] - 1
pair[-1][1] = len(z) - 1 - ans[-1]
l = 0
maxa = 0
ye = 0
inde = 0
k = b
if len(ans) <= k:
print(len(z))
ans = [(1) for i in range(len(z))]
print(*ans)
exit()
for i in range(len(ans) - k + 1):
ye = pair[i][0] + pair[i + k - 1][1] + ans[i + k - 1] - ans[i] + 1
if ye > maxa:
maxa = ye
inde = i
for i in range(ans[inde], len(z)):
if z[i] == 0:
z[i] = 1
k -= 1
if k == 0:
break
print(maxa)
print(*z)
|
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
PI = float("inf")
for _ in range(1):
n, k = lst()
ps = [0] * n
a = lst()
for i in range(n):
if a[i] == 0:
ps[i] = ps[max(0, i - 1)] + 1
else:
ps[i] = ps[max(0, i - 1)]
l = r = 0
p1 = p2 = -1
ln = 0
while r < n:
if ps[r] - (ps[l - 1] if l >= 1 else 0) > k:
l += 1
elif r < n and ps[r] - (ps[l - 1] if l >= 1 else 0) <= k and r - l + 1 >= ln:
ln = r - l + 1
p1 = l
p2 = r
r += 1
else:
r += 1
if l == r:
r += 1
ln = 0
for i in range(p1, p2 + 1):
a[i] = 1
c = mx = 0
for i in range(n):
if a[i] == 1:
c += 1
else:
c = 0
mx = max(mx, c)
print(mx)
print(*a)
|
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 STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
r = -1
ans = 0
ans_po = 0
for l in range(n):
if l > 0:
if a[l - 1] == 0:
m += 1
while r < n - 1 and 1 - a[r + 1] <= m:
r += 1
if a[r] == 0:
m = m - 1
if r - l + 1 > ans:
ans = r - l + 1
ans_po = l
print(ans)
for i in range(ans_po, ans_po + ans):
a[i] = 1
print(" ".join(map(str, a)))
|
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
def main():
n, k = list(map(int, input().split()))
nums = input().split()
nums.append("0")
n += 1
maxr = maxi = front = rear = 0
while front < n:
for front in range(front, n):
if nums[front] == "0":
if k > 0:
k -= 1
else:
break
r = front - rear
if r > maxr:
maxr = r
maxi = rear
if nums[rear] == "0":
if front > rear:
k += 1
else:
front += 1
rear += 1
nums.pop()
nums[maxi : maxi + maxr] = ("1" for _ in range(maxr))
print(maxr)
print(" ".join(nums))
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR STRING IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
def read_ints():
return [int(x) for x in input().split()]
def main():
n, k = read_ints()
a = read_ints()
lo = 0
hi = 0
count = 0
x = -1
y = -1
while hi < n:
if count < k or a[hi] != 0:
if a[hi] == 0:
count += 1
if hi - lo >= y - x:
x = lo
y = hi
hi += 1
else:
if a[lo] == 0:
count -= 1
lo += 1
if x != -1:
print(y - x + 1)
for i in range(x, y + 1):
a[i] = 1
print(" ".join(map(str, a)))
else:
print(0)
print(" ".join(map(str, a)))
main()
|
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
a, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
zeros = 0
left = 0
right = 0
consec = 0
best = 0
switch = []
best_coords = 0, 0
if k == 0:
for i in range(len(arr)):
if arr[i] == 1:
consec += 1
if consec > best:
best = consec
else:
consec = 0
else:
while right < len(arr):
if arr[right] == 0 and zeros + 1 > k:
while arr[left] == 1:
left += 1
consec -= 1
zeros -= 1
left += 1
consec -= 1
else:
if arr[right] == 0:
zeros += 1
consec += 1
right += 1
if consec > best:
best = consec
best_coords = left, right
print(best)
ans = ""
for i in range(len(arr)):
if best_coords[0] <= i < best_coords[1]:
ans += "1 "
else:
ans += str(arr[i]) + " "
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
import sys
input = sys.stdin.readline
def prog():
n, k = map(int, input().split())
a = list(map(int, input().split())) + [0]
count = 0
for i in range(n):
if a[i] == 1:
count += 1
if count + k >= n:
print(n)
print("1 " * n)
elif k == 0:
last = 0
mx = 0
for i in range(n):
if a[i] == 1 and a[i + 1] == 0:
mx = max(mx, i - last + 1)
if a[i] == 0 and a[i + 1] == 1:
last = i + 1
print(mx)
a.pop()
print(*a)
else:
zero_locs = []
for i in range(n):
if a[i] == 0:
zero_locs.append(i)
suffix = [0] * (n + 2)
prefix = [0] * (n + 2)
last = 0
for i in range(n):
if a[i] == 1 and a[i + 1] == 0:
suffix[i + 1] = i - last + 1
prefix[last + 1] = i - last + 1
if a[i] == 0 and a[i + 1] == 1:
last = i + 1
mx = 0
best = k - 1
for r in range(k - 1, len(zero_locs)):
amt = (
zero_locs[r]
- zero_locs[r - (k - 1)]
+ 1
+ suffix[zero_locs[r - (k - 1)]]
+ prefix[zero_locs[r] + 2]
)
if amt > mx:
mx = amt
best = r
a.pop()
for i in range(zero_locs[best - (k - 1)], zero_locs[best] + 1):
a[i] = 1
print(mx)
print(*a)
prog()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
from sys import stdin
def main():
n, k = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
start = 0
end = -1
zeros = 0
ans = 0
sid = -1
eid = -2
while end < n:
while end < n and zeros <= k:
end += 1
if end < n and ar[end] == 0:
zeros += 1
if ans < end - start:
ans = end - start
sid = start
eid = end - 1
while start <= end and zeros > k:
if ar[start] == 0:
zeros -= 1
start += 1
for i in range(sid, eid + 1):
ar[i] = 1
print(ans)
print(*ar)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if 0 not in a:
print(n)
print(*a)
exit()
if 1 not in a:
print(k)
res = [1] * k + [0] * (n - k)
print(*res)
exit()
zeroes = []
max_ones = 0
ones = 0
for i in range(n):
if a[i] == 0:
zeroes.append(i)
max_ones = max(max_ones, ones)
ones = 0
else:
ones += 1
max_ones = max(max_ones, ones)
if k == 0:
print(max_ones)
print(*a)
exit()
if len(zeroes) <= k:
print(n)
res = [1] * n
print(*res)
exit()
first = 0
last = k - 1
res = 0
res_first = 0
while last < len(zeroes):
before = zeroes[first] - zeroes[first - 1] - 1 if first > 0 else zeroes[first]
after = (
zeroes[last + 1] - zeroes[last] - 1
if last < len(zeroes) - 1
else n - zeroes[last] - 1
)
cnt = zeroes[last] - zeroes[first] + 1 + after + before
if cnt > res:
res = cnt
res_first = zeroes[first] - before
last += 1
first += 1
print(res)
ans = a[0:res_first] + [1] * res + a[res_first + res :]
print(*ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP LIST NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
ki = i = s = 0
po = 1
for j in range(n):
s += l[j] == 0
while s > k:
s -= l[i] == 0
i += 1
if j - i > ki - po:
po, ki = i, j
print(ki - po + 1)
l[po : ki + 1] = [1] * (ki - po + 1)
print(" ".join(map(str, l)))
|
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 VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = []
for i in range(n):
if a[i] == 0:
s.append(i)
z = 0
c = 0
x, w = 0, 0
for i in range(len(s) - k):
y = s[i + k] - z
if c < y:
c = y
x = z
w = s[i + k]
z = s[i] + 1
y = n - z
if c < y:
c = y
x = z
w = n
for i in range(x, w):
if a[i] == 0:
a[i] = 1
print(c)
for i in range(n):
print(a[i], end=" ")
print()
|
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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
bl, br, bv = -1, -1, 0
l = 0
c = 0
r = 0
while r < n:
if a[r] == 0:
if c < k:
c += 1
else:
if r - l > bv:
bv = r - l
bl = l
br = r
while a[l] == 1:
l += 1
l += 1
r += 1
if r - l > bv:
bv = r - l
bl = l
br = r
print(bv)
for i in range(n):
if i >= bl and i < br:
print(1, end=" ")
else:
print(a[i], end=" ")
|
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 VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
def main():
n, k = list(map(int, input().split()))
l, x = list(input()[::2]), k + 1
l.append("0")
n += 1
for i, c in enumerate(l):
if c == "0":
x -= 1
if not x:
break
m, j, ji = i, -1, (-1, i)
for i in range(i + 1, n):
if l[i] == "0":
for j in range(j + 1, n):
if l[j] == "0":
if m < i - j:
m, ji = i - j, (j, i)
break
j, i = ji
j += 1
z = i - j
l[j:i] = ["1"] * z
if z > n:
z = n
del l[-1]
print(z)
print(" ".join(l))
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST STRING VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
import sys
n, k = map(int, sys.stdin.buffer.readline().split())
a = [0] + list(map(int, sys.stdin.buffer.readline().split()))
zero = [0] * (n + 1)
for i in range(1, n + 1):
zero[i] = zero[i - 1] + (1 if a[i] == 0 else 0)
def solve(x):
for i in range(x, n + 1):
if zero[i] - zero[i - x] <= k:
return i
return -1
ok, ng = 0, n + 1
while abs(ok - ng) > 1:
mid = ok + ng >> 1
if solve(mid) != -1:
ok = mid
else:
ng = mid
r = solve(ok)
a[r - ok + 1 : r + 1] = [1] * ok
sys.stdout.buffer.write((str(ok) + "\n" + " ".join(map(str, a[1:]))).encode("utf-8"))
|
IMPORT 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER STRING
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
L = list(map(int, input().split()))
n = L[0]
k = L[1]
a = list(map(int, input().split()))
nbr0 = 0
posi = 0
taillemax = 0
p = 0
for i in range(len(a)):
nbr0 += a[i] == 0
if nbr0 > k:
if i - posi > taillemax:
p = posi
taillemax = i - posi
j = posi
while 1:
if a[j] == 0:
posi = j + 1
break
j = j + 1
nbr0 -= 1
if i == n - 1 and i - posi + 1 > taillemax:
p = posi
taillemax = i - posi + 1
print(taillemax)
ch = ""
for i in range(len(a)):
if i >= p and i < p + taillemax:
ch += "1 "
else:
ch += str(a[i]) + " "
print(ch)
|
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
x, y, m, ans = 0, 0, 0, [0, 0]
while x < n:
while y < n and (k > 0 or a[y] == 1):
if a[y] == 0:
k -= 1
y += 1
if y - x > m:
ans = [x, y]
m = y - x
if a[x] == 0:
k += 1
x += 1
a[ans[0] : ans[1]] = [1] * (ans[1] - ans[0])
print(ans[1] - ans[0])
print(" ".join(map(str, 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 VAR VAR VAR NUMBER NUMBER NUMBER LIST NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
mx = 0
def f(need, c, k, n):
for i in range(n):
if i + need - 1 >= n:
break
temp = c[i + need - 1]
if i > 0:
temp -= c[i - 1]
if temp + k >= need:
return True, i
return False, None
def main():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
c = [(0) for i in range(n)]
c[0] = a[0]
for i in range(1, n):
c[i] = c[i - 1]
if a[i] == 1:
c[i] += 1
l, r = k, n + 1
while r - l > 100:
m = (l + r) // 2
if f(m, c, k, n)[0]:
l = m
else:
r = m
for i in range(r, l - 1, -1):
res, start = f(i, c, k, n)
if res:
print("%d" % i)
print(" ".join(str(x) for x in a[:start] + [1] * i + a[start + i :]))
return
def __starting_point():
main()
__starting_point()
|
ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER VAR RETURN NUMBER NONE FUNC_DEF 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 VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP LIST NUMBER VAR VAR BIN_OP VAR VAR RETURN FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
l = 0
ans = 0
resL = -1
resR = -1
cntZero = 0
for r in range(n):
if a[r] == 0:
cntZero += 1
while cntZero > k:
if a[l] == 0:
cntZero -= 1
l += 1
if ans < r - l + 1:
ans = r - l + 1
resL = l
resR = r
print(ans)
if resL != -1:
for i in range(resL, resR + 1):
a[i] = 1
for i in range(n):
print(a[i], end=" ")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n = input().split()
k = int(n[-1])
n = int(n[0])
a = [int(x) for x in input().split()]
ii = 0
zero = list()
for x in a:
if not x:
zero.append(ii)
ii += 1
if len(zero) - k <= 0:
print(n)
string = "1"
for x in range(1, n):
string += " 1"
print(string)
elif k == 0:
string = ""
for x in range(len(a)):
string += str(a[x])
o = ""
while string.find(o + "1") != -1:
o += "1"
print(len(o))
print(" ".join(str(x) for x in a))
else:
maxof1 = 0
for i in range(len(zero) - k + 1):
z = 1
l1 = 0
while zero[i] - z >= 0 and a[zero[i] - z]:
l1 += 1
z += 1
z = 1
l2 = 0
while zero[i + k - 1] + z <= n - 1 and a[zero[i + k - 1] + z]:
l2 += 1
z += 1
x = zero[i + k - 1] - zero[i] + 1 + l1 + l2
if maxof1 < x:
maxof1 = x
maxn = i
print(maxof1)
for i in range(maxn, maxn + k):
a[zero[i]] = 1
string = str(a[0])
for x in range(1, len(a)):
string += " " + str(a[x])
print(string)
|
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 ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR BIN_OP VAR STRING NUMBER VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
i = 0
j = 0
Ansp = [0, 0]
zcnt = 0
max = 0
while i <= n - 1:
while j < n:
if zcnt >= k and a[j] == 0:
break
j += 1
if not a[j - 1]:
zcnt += 1
if zcnt > k:
j -= 1
zcnt -= 1
break
l = j - i
if l > max:
max = l
Ansp = [i, j]
if not a[i]:
zcnt -= 1
i += 1
for i in range(Ansp[0], Ansp[1]):
a[i] = 1
print(max)
print(" ".join(map(str, a)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
ch = input()
ch1 = input()
ch = ch.split(" ")
n = int(ch[0])
k = int(ch[1])
l = ch1.split(" ")
l = [int(i) for i in l]
nb = l.count(0)
if k >= nb:
print(n)
l = ["1"] * n
ch2 = " ".join(l)
print(ch2)
else:
c = 0
t = []
while len(t) < nb:
if l[c] == 0:
t.append(c)
c = c + 1
m = 0
j = 0
while j + k + 1 < nb:
d = t[j + k + 1] - t[j] - 1
j = j + 1
if m < d:
m = d
c = j
if m < t[k]:
m = t[k]
c = 0
if m < n - 1 - t[nb - k - 1]:
m = n - 1 - t[nb - k - 1]
c = nb - k
for i in range(c, c + k):
l[t[i]] = 1
l = [str(i) for i in l]
ch2 = " ".join(l)
print(m)
print(ch2)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
b = list(map(int, input().split()))
c = [0]
for j in range(n):
if b[j] == 0:
c.append(j)
j = 0
strt = 0
m = 0
q = 0
s = 0
p = 0
while j < n:
if b[j] == 0:
p += 1
if p > k:
if q != 0:
s += 1
q += 1
s += -(c[q] - c[q - 1])
strt = c[q] + 1
p -= 1
else:
s += 1
else:
s += 1
if s >= m:
m = s
x = strt
y = j
j += 1
j = x
while j <= y:
b[j] = 1
j += 1
print(m)
print(*b)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
class MaxSum(object):
def __init__(self, init_list):
self.l = init_list
self.subl = []
def max_sum(self):
sum = 0
ans = 0
if max(self.l) < 0:
return 0
for x in self.l:
sum += x
ans = sum if sum > ans else ans
if sum < 0:
sum = 0
return ans
n, k = map(int, input().split())
lk = list(map(int, input().split()))
l1 = [(1 - i) for i in lk]
l = r = lm = lr = 0
su = l1[0]
ma = 1
ind = 1
if k > 0:
while su <= k:
if ind == n:
break
if su + l1[ind] <= k:
r += 1
su += l1[ind]
ma += 1
ind += 1
else:
break
rm = r
while r + 1 < n:
while l1[l] == 0:
l += 1
l += 1
r += 1
if r == n - 1:
if r + 1 - l > ma:
ma = r + 1 - l
lm = l
rm = r
break
while l1[r + 1] == 0:
r += 1
if r == n - 1:
break
if r + 1 - l > ma:
ma = r + 1 - l
lm = l
rm = r
print(ma)
else:
print(MaxSum([(-n if i == 0 else 1) for i in lk]).max_sum())
if k == 0:
print(*lk)
else:
for i in range(lm, rm + 1):
lk[i] = 1
print(*lk)
|
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split(" "))
a = list(map(int, input().split()))
arr = [-1]
for i in range(n):
if a[i] == 0:
arr.append(i)
arr.append(n)
if len(arr) - 2 <= k:
ans = [1] * n
print(n)
print(*ans)
else:
x = len(arr)
ans = 0
start = 0
end = -1
for i in range(k + 1, x):
if ans < arr[i] - arr[i - k - 1] - 1:
start = arr[i - k - 1] + 1
end = arr[i] - 1
ans = arr[i] - arr[i - k - 1] - 1
for i in range(start, end + 1):
a[i] = 1
print(ans)
print(*a)
|
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 ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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 VAR IF VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
import sys
n, k = [int(a) for a in input().split()]
As = [int(a) for a in input().split()]
groupstart = [0] * n
for i in range(1, n):
if As[i - 1] == As[i]:
groupstart[i] = groupstart[i - 1]
else:
groupstart[i] = i
groupend = [n] * n
for i in range(n - 2, -1, -1):
if As[i] == As[i + 1]:
groupend[i] = groupend[i + 1]
else:
groupend[i] = i + 1
def nochange():
print(max([0] + [(groupend[i] - groupstart[i]) for i in range(n) if As[i] == 1]))
print(" ".join([str(a) for a in As]))
sys.exit()
def allones():
print(n)
print(" ".join(["1" for a in As]))
sys.exit()
if k == 0:
nochange()
low = 0
try:
low = As.index(0)
except ValueError:
allones()
high = low
j = 0
while j < k:
if As[high] == 0:
j += 1
high += 1
if high == n:
allones()
best = 0
bestlow = low
besthigh = high
while high <= n:
fa = low if low == 0 or As[low - 1] == 0 else groupstart[low - 1]
fb = high if high == n or As[high] == 0 else groupend[high]
f = fb - fa
if best < f:
best = f
bestlow = low
besthigh = high
if high == n:
break
low += 1
if As[low] == 1:
low = groupend[low]
if As[high] == 1:
high = groupend[high]
high += 1
print(best)
for i in range(bestlow, besthigh):
As[i] = 1
print(" ".join([str(a) for a in As]))
|
IMPORT 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 FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING STRING VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
z = 0
zeros = []
for i in range(n):
if arr[i] == 1:
z += 1
else:
zeros.append([i, z])
if len(zeros) > 1:
zeros[-2].append(z)
z = 0
try:
zeros[-1].append(z)
except:
print(n)
print(*arr)
exit()
if k == 0:
print(max(max(zeros, key=lambda x: max(x[1], x[2]))[1:]))
print(*arr)
elif len(zeros) <= k:
print(n)
print(*[(1) for i in range(n)])
else:
maxi = [-1, -1]
for i in range(len(zeros) - k + 1):
diff = zeros[i][1] + zeros[i + k - 1][2] + zeros[i + k - 1][0] - zeros[i][0] + 1
if diff > maxi[0]:
maxi = [diff, i]
for i in range(zeros[maxi[1]][0], zeros[maxi[1] + k - 1][0] + 1):
arr[i] = 1
print(maxi[0])
print(*arr)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
s = list(map(int, input().split()))
ans = 0
def get(x):
return 1 - x
l = 0
r = -1
cnt = 0
L = n
R = 0
while l < n:
while r + 1 < n and cnt + get(s[r + 1]) <= k:
cnt += get(s[r + 1])
r += 1
now = r - l + 1
if now > ans:
ans = now
L = l
R = r
cnt -= get(s[l])
l += 1
for i in range(L, R + 1):
s[i] = 1
print(ans)
print(" ".join(map(str, s)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = list(map(int, input().split()))
m = list(map(int, input().split()))
ls = [0]
now = 0
for i in range(n):
now += m[i]
ls += [now]
s = 1
bz = 0
locs = [0, 0]
for i in range(1, n + 1):
su = ls[i] - ls[s - 1]
t = i - s + 1
if t - su <= k:
if bz < t:
bz = t
locs = [s, i]
else:
t = i - s + 1
su = ls[i] - ls[s - 1]
while t - su > k:
s += 1
t = i - s + 1
su = ls[i] - ls[s - 1]
m[locs[0] - 1 : locs[1]] = [1] * bz
print(bz)
print(*m)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
import sys
n, k = map(int, input().split())
a = list(map(int, sys.stdin.readline().split()))
l = 0
r = 0
zeroCount = 0
ans = 0
imax = 0
for i in range(n):
if a[i] == 1:
r += 1
elif zeroCount == k:
while a[l] != 0:
l += 1
l += 1
r += 1
else:
zeroCount += 1
r += 1
if r - l > ans:
ans = r - l
imax = r
for i in range(imax - ans, imax):
a[i] = 1
print(ans)
print(*a)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
m = 0
z = 0
p = 0
r = 0
for i in range(n):
if l[i] == 0:
z += 1
if z <= k:
m += 1
r = i
else:
if l[p] == 0:
z -= 1
p += 1
print(m)
l[r - m + 1 : r + 1] = [1] * m
print(*l)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
i = j = ss = ee = aa = 0
countzero = 0
while i < n:
while countzero <= k and i < n:
if a[i] == 0:
countzero += 1
i += 1
if i - j + 1 > aa and countzero <= k:
ss = i
ee = j
aa = i - j
while countzero > k:
if a[j] == 0:
countzero -= 1
j += 1
if i - j + 1 > aa and countzero <= k:
ss = i
ee = j
aa = i - j
print(aa)
for k in range(ee, ss):
a[k] = 1
print(*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 VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
3
__metaclass__ = type
__author__ = "xdlove"
n, k = list(map(int, input().split()))
res = [int(x) for x in input().split()]
l, r = -1, -2
L, num_0 = 0, 0
for R in range(n):
if res[R] == 0:
num_0 += 1
while num_0 > k:
if r - l < R - L:
l, r = L, R
if res[L] == 0:
num_0 -= 1
L += 1
if R == n - 1 and r - l < R + 1 - L:
l, r = L, R + 1
print(r - l)
for i in range(n):
if l <= i < r:
res[i] = 1
res[i] = str(res[i])
print(" ".join(res))
|
EXPR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL 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 NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 0
ans = 0
ans_pr = [0, 0]
ct = 0
while l < n:
while r < n and (a[r] or ct < k):
ct += not a[r]
r += 1
if r - l > ans:
ans = r - l
ans_pr = [l, r]
ct -= not a[l]
l += 1
print(ans)
print(*(a[: ans_pr[0]] + [1] * ans + a[ans_pr[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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP LIST NUMBER VAR VAR VAR NUMBER
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
arr = [int(i) for i in input().split()]
pref = [0]
for i in range(n):
pref.append(pref[-1] + arr[i])
def sat(low, ind):
global k
return pref[ind + 1] - pref[low] >= ind - low + 1 - k
def bs(lo, hi):
ret = -1
low = lo
while lo <= hi:
mid = (lo + hi) // 2
if sat(low, mid):
ret = max(ret, mid)
lo = mid + 1
else:
hi = mid - 1
return ret
ans = 0
start = 0
for i in range(n):
length = bs(i, n - 1) - i + 1
if length > ans:
ans = length
start = i
print(ans)
for i in range(start, start + ans):
arr[i] = 1
print(*arr)
|
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 LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
A = [int(x) for x in input().split()]
a, b, c = 0, 0, 0
fa, fl = 0, 0
while b < len(A):
while b < len(A) and c <= k:
if b - a > fl:
fl = b - a
fa = a
if A[b] == 0:
c += 1
b += 1
while c > k and a <= b:
if A[a] == 0:
c -= 1
a += 1
c = max([0, c])
if b - a > fl:
fl = b - a
fa = a
print(fl)
for i in range(len(A)):
print(1 if fa <= i and i < fa + fl else A[i], end=" ")
|
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 VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR STRING
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
import sys
f = sys.stdin.readline
n, k = map(int, f().strip().split())
arr = [int(v) for v in f().strip().split()]
zr = 0
i = 0
j = 0
ans = -1
ids = [0] * n
while i < n:
while j < n and zr <= k:
if arr[j] == 0:
zr += 1
j += 1
ans = max(ans, j - i - 1) if zr > k else max(ans, j - i)
ids[i] = ans
if arr[i] == 0:
zr -= 1
i += 1
print(ans)
i = ids.index(ans)
arr = arr[:i] + [1] * ans + arr[i + ans :]
print(" ".join(map(str, arr)))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP LIST NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
n, k = map(int, input().split())
lis = list(map(int, input().split()))
zer = [0] * (n + 1)
for i in range(n):
if lis[i] == 0:
zer[i + 1] = zer[i] + 1
else:
zer[i + 1] = zer[i]
ind = ans = 0
for i in range(n):
l = i + 1
r = n
while l <= r:
mid = l + (r - l) // 2
ze = zer[mid] - zer[i]
if ze > k:
r = mid - 1
else:
l = mid + 1
if zer[r] - zer[i] <= k and r - i > ans:
ans = r - i
ind = i
i = ind
while i < n and k:
if lis[i] == 0:
lis[i] = 1
k -= 1
i += 1
print(ans)
print(*lis)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
fd = open("input.txt", "r")
fd1 = open("output.txt", "w")
n = int(fd.readline())
arr = list(map(int, fd.readline().split()))
freq = [(0) for i in range(5001)]
for i in range(n):
freq[arr[i]] += 1
presum = [(0) for i in range(5001)]
for i in range(1, 5001):
presum[i] = presum[i - 1] + freq[i]
tot = n
mini = n
for i in range(1, 5001):
maxa = 2 * i
if maxa > 5001:
break
ans = n - (presum[maxa] - presum[i] + freq[i])
mini = min(mini, ans)
fd1.write(str(mini))
|
ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING 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 NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
import sys
def main():
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n, res, j = int(input()), [], 0
cc, f = sorted(map(int, input().split())), res.append
for i, c in enumerate(cc):
while cc[j] * 2 < c:
j += 1
f(i - j)
print(n - max(res) - 1)
def __starting_point():
main()
__starting_point()
|
IMPORT FUNC_DEF IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n = int(input())
t = list(map(int, sys.stdin.readline().split()))
p = [0] * 5001
for i in t:
p[i] += 1
q = p[:]
for i in range(1, 5001):
q[i] += q[i - 1]
ans = q[5000] - q[2499]
for i in range(1, 2501):
if p[i]:
s = q[2 * i] - q[i - 1]
if s > ans:
ans = s
print(n - ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING 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 NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
with open("input.txt") as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
mark = [(0) for _ in range(5001)]
sumMark = [(0) for _ in range(5001)]
total = 0
minA = 1000000
for v in arr:
mark[v] += 1
total += 1
for i in range(1, 5001):
if mark[i] > 0:
sumMark[i] = sumMark[i - 1] + mark[i]
else:
sumMark[i] = sumMark[i - 1]
for i in range(1, 5001):
if i <= 2500:
if mark[i] > 0:
preValue = sumMark[i - 1]
postValue = total - sumMark[i * 2]
remove = postValue + preValue
ret = total - remove
if remove < minA:
minA = remove
elif mark[i] > 0:
remove = sumMark[i - 1]
ret = total - remove
if remove < minA:
minA = remove
with open("output.txt", "w") as f:
f.write(str(minA))
|
FUNC_CALL VAR STRING 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 NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n = int(input())
res = [int(t) for t in input().split()]
res.sort()
min_erase = n
i, j = 0, 0
while i != n - 1:
if res[j] <= 2 * res[i]:
ans = True
if n - (j - i + 1) < min_erase:
min_erase = n - (j - i + 1)
else:
ans = False
if ans and j != n - 1:
j += 1
else:
i += 1
print(min_erase)
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING 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 VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
def solve(seq):
n = len(seq)
cnt = [0] * 5001
for e in seq:
cnt[e] += 1
acc = [0]
for i in range(1, 5001):
acc.append(acc[-1] + cnt[i])
ans = n
for i in range(5001):
if cnt[i] > 0:
n2remove = n - acc[min(2 * i, 5000)] + acc[i - 1]
ans = min(ans, n2remove)
return ans
def main():
with open("input.txt") as f:
_ = int(f.readline())
seq = list(map(int, f.readline().split()))
ans = solve(seq)
with open("output.txt", "w") as f:
f.write(str(ans))
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF FUNC_CALL VAR STRING 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 FUNC_CALL VAR STRING STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
f = open("input.txt", "r")
n = int(f.readline())
c = sorted(map(int, f.readline().split()))
j, v = 0, n - 1
for i in range(n):
while j < n - 1 and 2 * c[i] >= c[j + 1]:
j += 1
v = min(v, n + i - j - 1)
open("output.txt", "w").write(str(v))
|
ASSIGN VAR FUNC_CALL VAR STRING STRING 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL FUNC_CALL VAR STRING STRING FUNC_CALL VAR VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
import sys
sys.stdin = open("input.txt")
sys.stdout = open("output.txt", "+w")
n = int(input())
a = [0] + sorted(list(map(int, input().split())))
start = 1
res = 0
for end in range(1, n + 1):
while a[end] > 2 * a[start]:
start += 1
res = max(res, end - start + 1)
print(n - res)
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER 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 WHILE VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
f = open("input.txt", "r")
f1 = open("output.txt", "w")
def search(mas, val):
p = 0
ost = len(mas) - 1
while p <= ost:
mid = (p + ost) // 2
if mas[mid] > val * 2:
ost = mid - 1
else:
p = mid + 1
return p
n = int(f.readline())
ma = n - 1
l = list(map(int, f.readline().split()))
l = sorted(l)
for i in range(n):
e = search(l, l[i])
w = i + n - e
ma = min(ma, w)
ma = str(ma)
f1.write(ma)
f.close()
f1.close()
|
ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result x, and the largest result y, then the inequality y ≤ 2·x must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
-----Input-----
The first line contains integer n (2 ≤ n ≤ 10^5) — the number of measurements Vasya made. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
-----Output-----
Print a single integer — the minimum number of results Vasya will have to remove.
-----Examples-----
Input
6
4 5 3 8 3 7
Output
2
Input
4
4 3 2 4
Output
0
-----Note-----
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
class CodeforcesTask253BSolution:
def __init__(self):
self.result = ""
self.measure_count = 0
self.measurements = []
def read_input(self):
in_ = open("input.txt", "r").read().split("\n")
self.measure_count = int(in_[0])
self.measurements = [int(x) for x in in_[1].split(" ")]
def process_task(self):
occurs = [(0) for x in range(5000)]
for m in self.measurements:
occurs[m - 1] += 1
dels = [(sum(occurs[: m - 1]) + sum(occurs[m * 2 :])) for m in range(1, 5000)]
self.result = str(min(dels))
def get_result(self):
return self.result
def __starting_point():
Solution = CodeforcesTask253BSolution()
Solution.read_input()
Solution.process_task()
open("output.txt", "w").write(Solution.get_result())
__starting_point()
|
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER STRING FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR STRING STRING FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score.
Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces.
Output
Print the maximum possible number of points you can score.
Examples
Input
10 3 2
1 2 1 1 3 2 1 1 2 2
Output
4
Input
10 2 2
1 2 1 2 1 1 2 1 1 2
Output
5
Input
3 1 2
1 1 1
Output
3
Note
In the first sample you should delete the fifth and the sixth cubes.
In the second sample you should delete the fourth and the seventh cubes.
In the third sample you shouldn't delete any cubes.
|
R = lambda: map(int, input().split())
n, m, k = R()
arr = list(R())
arrs = [list() for i in range(m)]
for i, x in enumerate(arr):
arrs[x - 1].append(i)
res = 1
for ar in arrs:
l = -1
for r in range(len(ar)):
while r - l + k < ar[r] - ar[l + 1] + 1:
l += 1
res = max(res, r - l)
print(res)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score.
Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces.
Output
Print the maximum possible number of points you can score.
Examples
Input
10 3 2
1 2 1 1 3 2 1 1 2 2
Output
4
Input
10 2 2
1 2 1 2 1 1 2 1 1 2
Output
5
Input
3 1 2
1 1 1
Output
3
Note
In the first sample you should delete the fifth and the sixth cubes.
In the second sample you should delete the fourth and the seventh cubes.
In the third sample you shouldn't delete any cubes.
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
col = [[] for i in range(m + 1)]
for i in range(n):
col[a[i]] += [i]
pref_c = [([0] * len(col[i])) for i in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, len(col[i])):
pref_c[i][j] = pref_c[i][j - 1] + col[i][j] - col[i][j - 1] - 1
ans = 1
for i in range(1, m + 1):
r = 1
for j in range(len(col[i])):
while r < len(col[i]) and pref_c[i][r] - pref_c[i][j] <= k:
r += 1
ans = max(ans, r - j)
print(ans)
|
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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score.
Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces.
Output
Print the maximum possible number of points you can score.
Examples
Input
10 3 2
1 2 1 1 3 2 1 1 2 2
Output
4
Input
10 2 2
1 2 1 2 1 1 2 1 1 2
Output
5
Input
3 1 2
1 1 1
Output
3
Note
In the first sample you should delete the fifth and the sixth cubes.
In the second sample you should delete the fourth and the seventh cubes.
In the third sample you shouldn't delete any cubes.
|
from sys import stdin, stdout
n, q, k = map(int, stdin.readline().split())
colours = list(map(int, stdin.readline().split()))
position = [[] for i in range(q + 1)]
cnt = [[] for i in range(q + 1)]
ans = 0
c, l, r = colours[0], 0, 0
for i in range(1, n):
if colours[i] != c:
position[c].append([l, r])
c = colours[i]
l, r = i, i
else:
r += 1
position[c].append([l, r])
for i in range(1, q + 1):
if position[i]:
cnt[i].append((position[i][0][1] - position[i][0][0] + 1, 0))
for j in range(1, len(position[i])):
cnt[i].append(
(
cnt[i][j - 1][0] + position[i][j][1] - position[i][j][0] + 1,
cnt[i][j - 1][1] + position[i][j][0] - position[i][j - 1][1] - 1,
)
)
cnt[i].append((0, 0))
l = 0
r = n + 1
while r - l > 1:
m = (r + l) // 2
label = 1
mx = 0
for i in range(1, q + 1):
if not len(position[i]):
continue
for j in range(len(position[i])):
lb, rb = j - 1, len(position[i])
while rb - lb > 1:
mb = (rb + lb) // 2
if cnt[i][mb][1] - cnt[i][j][1] > k:
rb = mb
else:
lb = mb
mx = max(cnt[i][lb][0] - cnt[i][j - 1][0], mx)
if mx < m:
r = m
else:
l = m
stdout.write(str(l))
|
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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input().rstrip()
if "a" not in s or "b" not in s:
print(n)
exit()
a = [0]
b = [0]
for ch in s:
a.append(a[-1] + (ch == "a"))
b.append(b[-1] + (ch == "b"))
def maxSize(a):
ret = 0
first = [-1] * n
for i, val in enumerate(a):
if first[val] == -1:
first[val] = i
if val <= k:
ret = max(ret, i)
elif first[val - k] != -1:
ret = max(ret, i - first[val - k])
return ret
print(max(maxSize(a), maxSize(b)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def testa_se_da(valor, a, k, a_b):
var = a_b
def consegue(soma):
if soma <= k:
return True
else:
return False
pos_esquerda = 0
n = len(a)
pos_direita = pos_esquerda + valor
soma = 0
for i in range(pos_esquerda, pos_direita):
if a[i] != var:
soma += 1
if consegue(soma):
return True
while pos_direita <= n - 1:
if a[pos_direita] != var:
soma += 1
if a[pos_esquerda] != var:
soma -= 1
if consegue(soma):
return True
pos_esquerda += 1
pos_direita += 1
return False
n, k = map(int, input().split())
a = [char for char in input()]
esquerda = 0
direita = n
melhor = 0
while esquerda <= direita:
meio = (esquerda + direita) // 2
da_a = testa_se_da(meio, a, k, "a")
da_b = testa_se_da(meio, a, k, "b")
if da_a or da_b:
if meio > melhor:
melhor = meio
esquerda = meio + 1
else:
direita = meio - 1
print(melhor)
|
FUNC_DEF ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def sol(n, k, a, e):
cnt = 0
l = 0
maxl = 0
for i in range(n):
if a[i] != e:
cnt += 1
while cnt > k:
if a[l] != e:
cnt -= 1
l += 1
maxl = max(maxl, i - l + 1)
return maxl
n, k = map(int, input().split())
s = input()
maxx = 0
for e in "ab":
v = sol(n, k, s, e)
maxx = max(maxx, v)
print(maxx)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
e, t = 0, 0
res = 0
for i in range(n):
if s[i] == "b":
t += 1
while t > k and e < i:
if s[e] == "b":
t -= 1
e += 1
res = max(res, i - e + 1)
e, t = 0, 0
for i in range(n):
if s[i] == "a":
t += 1
while t > k and e < i:
if s[e] == "a":
t -= 1
e += 1
res = max(res, i - e + 1)
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = list(input())
ans = 0
m = [0, 0]
l = 0
for i in s:
m[ord(i) - 97] += 1
if min(m) > k:
m[ord(s[l]) - 97] -= 1
l += 1
else:
ans += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
longest = 0
left, right = 0, 0
currb = 1 if s[0] == "b" else 0
while True:
while right < n and currb <= k:
right += 1
if right < n and s[right] == "b":
currb += 1
longest = max(longest, right - left)
if s[left] == "b":
currb -= 1
left += 1
if left == n or right == n:
break
left, right = 0, 0
currb = 1 if s[0] == "a" else 0
while True:
while right < n and currb <= k:
right += 1
if right < n and s[right] == "a":
currb += 1
longest = max(longest, right - left)
if s[left] == "a":
currb -= 1
left += 1
if left == n or right == n:
break
print(longest)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = list(map(int, input().split()))
s = input()
left = 0
changes = 0
record_a = 0
for i in range(len(s)):
if s[i] == "b":
changes += 1
if changes > k:
changes -= 1
while s[left] == "a":
left += 1
left += 1
record_a = max(record_a, i + 1 - left)
left = 0
changes = 0
record_b = 0
for i in range(len(s)):
if s[i] == "a":
changes += 1
if changes > k:
changes -= 1
while s[left] == "b":
left += 1
left += 1
record_b = max(record_b, i + 1 - left)
print(max(record_a, record_b))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = list(map(int, input().split()))
s = input()
l = 0
r = 0
ans = 0
num = 0
i = 0
while i < n:
r += 1
if s[i] == "b":
num += 1
if num > k:
ans = max(ans, i - l)
while l < n and s[l] != "b":
l += 1
l += 1
num -= 1
i += 1
ans = max(ans, i - l)
l = 0
r = 0
num = 0
i = 0
while i < n:
r += 1
if s[i] == "a":
num += 1
if num > k:
ans = max(ans, i - l)
while l < n and s[l] != "a":
l += 1
l += 1
num -= 1
i += 1
ans = max(ans, i - l)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
count = {"a": s.count("a"), "b": s.count("b")}
r = n
M = 0
l = 0
while l < n:
while count["a"] > k and count["b"] > k:
r -= 1
count[s[r]] -= 1
while r < n and (count["a"] <= k or count["b"] <= k):
count[s[r]] += 1
r += 1
if r - l > M:
if count["a"] > k and count["b"] > k:
M = r - l - 1
else:
M = r - l
l += 1
count[s[l - 1]] -= 1
print(M)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR STRING VAR VAR STRING VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR VAR STRING VAR VAR STRING VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR STRING VAR VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
string = input()
count = [0, 0]
j = out = 0
for i in range(n):
count[string[i] == "a"] += 1
if min(count) > k:
count[string[j] == "a"] -= 1
j += 1
else:
out += 1
print(out)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR STRING NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
maxi = res = 0
count = {"a": 0, "b": 0}
for i in range(n):
count[s[i]] += 1
maxi = max(maxi, count[s[i]])
if res - maxi < k:
res += 1
else:
count[s[i - res]] -= 1
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
l = 0
r = 0
ch = 0
maxa = 0
if k == 0:
maxa = 1
count = 1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
count += 1
else:
maxa = max(maxa, count)
count = 1
maxa = max(maxa, count)
print(maxa)
exit()
while l <= r and r < len(s) and ch <= k:
if s[r] == "a":
r += 1
maxa = max(r - l, maxa)
elif ch < k:
ch += 1
r += 1
else:
maxa = max(r - l, maxa)
if s[l] == "a":
l += 1
else:
l += 1
ch = ch - 1
maxa = max(maxa, r - l)
l = 0
r = 0
ch = 0
while l <= r and r < len(s) and ch <= k:
if s[r] == "b":
r += 1
maxa = max(r - l, maxa)
elif ch < k:
ch += 1
r += 1
else:
maxa = max(r - l, maxa)
if s[l] == "b":
l += 1
else:
l += 1
ch = ch - 1
maxa = max(maxa, r - l)
print(maxa)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
mx = 0
ac = 0
bc = 0
j = 0
for i in range(len(s)):
if s[i] == "a":
ac += 1
elif s[i] == "b":
bc += 1
if ac - k <= 0 or bc - k <= 0:
mx = ac + bc
else:
if s[j] == "a":
ac -= 1
else:
bc -= 1
j += 1
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, t = map(int, input().split())
s = input()
l = 0
k = 0
ma = 0
for r in range(n):
if s[r] == "a":
if r - l + 1 > ma:
ma = r - l + 1
else:
while k >= t:
if s[l] == "b":
k -= 1
l += 1
if r - l + 1 > ma:
ma = r - l + 1
k += 1
k %= r - l + 2
l = 0
k = 0
for r in range(n):
if s[r] == "b":
if r - l + 1 > ma:
ma = r - l + 1
else:
while k >= t:
if s[l] == "a":
k -= 1
l += 1
if r - l + 1 > ma:
ma = r - l + 1
k += 1
k %= r - l + 2
print(ma)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def solver(myStr, letter):
l, r = 0, 0
curr_k, best = 0, 0
while r < n:
if myStr[r] != letter:
curr_k += 1
if curr_k <= k:
best = max(best, r - l + 1)
else:
while curr_k > k:
if myStr[l] != letter:
curr_k -= 1
l += 1
r += 1
return best
n, k = map(int, input().split())
s = input()
print(max(solver(s, "a"), solver(s, "b")))
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
from itertools import accumulate
n, k = [int(x) for x in input().split()]
A = [(1 if c == "a" else 0) for c in input()]
P = [0] + list(accumulate(A))
x, y = 1, n + 1
z = n // 2
while x != z:
for i in range(n - z + 1):
t = P[i + z] - P[i]
if t >= z - k or t <= k:
x = z
break
else:
y = z
z = (x + y) // 2
print(z)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
def f(a):
if len(a) <= k:
return n
a = [-1] + a + [n]
return max(a[i] - a[i - k - 1] - 1 for i in range(k + 1, len(a)))
print(
max(
f([i for i, ch in enumerate(s) if ch == "a"]),
f([i for i, ch in enumerate(s) if ch == "b"]),
)
)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
pref = [0]
arr = [(0) for i in range(n)]
s = input()
for i in range(n):
arr[i] = ord(s[i]) - ord("a")
pref.append(pref[-1] + arr[i])
def sat(low, ind):
global k
return (
pref[ind + 1] - pref[low] <= k or pref[ind + 1] - pref[low] >= ind - low + 1 - k
)
def bs(lo, hi):
ret = -1
low = lo
while lo <= hi:
mid = (lo + hi) // 2
if sat(low, mid):
ret = max(ret, mid)
lo = mid + 1
else:
hi = mid - 1
return ret
ans = 0
for i in range(n):
ans = max(ans, bs(i, n - 1) - i + 1)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def vasia(n, k, w):
pos = 0
suma = 0
sumb = 0
con = 0
for i in range(n):
if w[i] == "a":
suma = suma + 1
elif w[i] == "b":
sumb = sumb + 1
if min(suma, sumb) <= k:
con = max(con, suma + sumb)
else:
res = w[pos]
if res == "a":
suma = suma - 1
elif res == "b":
sumb = sumb - 1
con = max(con, suma + sumb)
pos = pos + 1
return con
def main():
n, k = map(int, input().split())
w = list(input())
print(vasia(n, k, w))
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
lis = [[0, 0] for i in range(n + 1)]
s = list(input())
ans = 0
for i in range(1, n + 1):
if s[i - 1] == "a":
lis[i][0] = lis[i - 1][0] + 1
lis[i][1] = lis[i - 1][1]
else:
lis[i][1] = lis[i - 1][1] + 1
lis[i][0] = lis[i - 1][0]
for i in range(1, n + 1):
l = i
r = n
while l <= r:
mid = l + (r - l) // 2
ca = lis[mid][0] - lis[i - 1][0]
cb = lis[mid][1] - lis[i - 1][1]
chan = min(ca, cb)
if chan > k:
r = mid - 1
else:
l = mid + 1
ans = max(ans, r - i + 1)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = list(input())
aa = [0] * (n + 1)
bb = [0] * (n + 1)
res = 1
a, b = 0, 0
for i in range(1, n + 1):
if s[i - 1] == "a":
a += 1
aa[a] = i
else:
b += 1
bb[b] = i
res = max(res, i - aa[max(a - k, 0)])
res = max(res, i - bb[max(b - k, 0)])
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
a = input()
ka = 0
kb = 0
c = 0
answer = 0
for i in range(n):
if a[i] == "a":
ka += 1
else:
kb += 1
s = min(ka, kb)
if k < s:
if a[c] == "a":
ka -= 1
else:
kb -= 1
c += 1
else:
answer += 1
print(answer)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = list(input())
j = 0
answer = 0
counter = [0, 0]
for i in range(n):
if s[i] == "b":
counter[1] += 1
else:
counter[0] += 1
if min(counter) > k:
if s[j] == "a":
counter[0] -= 1
else:
counter[1] -= 1
j += 1
else:
answer += 1
print(answer)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def find(s, n, k, constant):
pref = [0]
for x in s:
if x == constant:
pref.append(pref[-1] + 1)
else:
pref.append(pref[-1])
i, j = 1, 1
ans = 0
while i <= n and j <= n:
nbs = pref[j] - pref[i - 1]
if nbs <= k:
ans = max(ans, j - i + 1)
j += 1
else:
i += 1
return ans
n, k = map(int, input().split())
s = input()
if k == 0:
ans = 0
cnt = 1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
cnt += 1
else:
ans = max(ans, cnt)
cnt = 1
ans = max(ans, cnt)
print(ans)
else:
ans = find(s, n, k, "b")
ans = max(ans, find(s, n, k, "a"))
print(ans)
|
FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
from sys import stdin
N, K = map(int, stdin.readline().split())
charArr = list(stdin.readline().strip())
bad = 0
front = 0
front2 = 0
back = len(charArr)
answer = K
while front < back:
if charArr[front] != "a":
bad += 1
if bad > K:
while front2 <= front and charArr[front2] == "a":
front2 += 1
bad -= 1
front2 += 1
answer = max(answer, front - front2 + 1)
front += 1
bad = 0
front = 0
front2 = 0
back = len(charArr)
while front < back:
if charArr[front] != "b":
bad += 1
if bad > K:
while front2 <= front and charArr[front2] == "b":
front2 += 1
bad -= 1
front2 += 1
answer = max(answer, front - front2 + 1)
front += 1
print(answer)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
I = lambda: int(input())
IL = lambda: list(map(int, input().split()))
n, k = IL()
s = input()
l1 = list(map(len, s.split("a")))
l2 = list(map(len, s.split("b")))
ms = cs = sum(l1[: k + 1]) + len(l1[: k + 1]) - 1
for i in range(len(l1) - k - 1):
cs += l1[i + k + 1] - l1[i]
ms = max(ms, cs)
cs = sum(l2[: k + 1]) + len(l2[: k + 1]) - 1
ms = max(ms, cs)
for i in range(len(l2) - k - 1):
cs += l2[i + k + 1] - l2[i]
ms = max(ms, cs)
print(ms)
|
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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def find_max(n, m, t, char="a"):
l = 0
r = 0
count = 0
ans = 0
num = 0
while r < n:
if t[r] == char:
count += 1
r += 1
elif t[r] != char and num < m:
count += 1
r += 1
num += 1
elif t[r] != char and num >= m:
ans = max(ans, count)
if l == -1:
l += 1
else:
if t[l] != char:
num -= 1
count -= 1
l += 1
ans = max(count, ans)
return ans
n, m = map(int, input().split())
t = input()
ans = max(find_max(n, m, t), find_max(n, m, t, "b"))
print(ans)
|
FUNC_DEF STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN 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 VAR VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def check(lengths, k, full_count_of_opposite):
maxcount = 0
count = 0
start = 0
cur_k = k
for i, el in enumerate(lengths):
if i % 2 == 0:
count += el
elif cur_k - el >= 0:
cur_k -= el
else:
maxcount = max(count, maxcount)
cur_k -= el
while start < i and cur_k < 0:
count -= lengths[start]
cur_k += lengths[start + 1]
start += 2
if start > i:
cur_k = k
count = 0
maxcount = max(count, maxcount)
result = maxcount + min(k, full_count_of_opposite)
return result
def maxsubsl(s, k):
lengths = []
prev = s[0]
cnt = 0
full_counts = [0, 0]
for el in s:
if el != prev:
lengths.append(cnt)
cnt = 0
prev = el
cnt += 1
full_counts[len(lengths) % 2] += 1
lengths.append(cnt)
maxl = check(lengths, k, full_counts[1])
if len(lengths) > 1:
maxl = max(maxl, check(lengths[1:], k, full_counts[0]))
return maxl
_, k = list(map(int, input().split()))
s = input()
print(maxsubsl(s, k))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
import sys
input = sys.stdin.readline
def prog():
n, k = map(int, input().split())
string = input().strip()
if k == 0:
print(max(max(map(len, string.split("a"))), max(map(len, string.split("b")))))
else:
ka = k
for i in range(n):
if string[i] == "b":
ka -= 1
if ka == 0:
break
stop = False
for i in range(i + 1, n):
if string[i] != "a":
stop = True
break
i = i - stop
maxa = i + 1
curr_total = i + 1
curr_start = string.find("b")
curr_end = i
while curr_end < n - 1:
if string[curr_start] == "b":
lost = 0
i = curr_start - 1
while string[i] == "a" and i >= 0:
lost += 1
i -= 1
i = curr_end + 1
added = 0
not_changed = True
while i < n and (string[i] == "a" or not_changed):
if string[i] == "b":
not_changed = False
added += 1
i += 1
curr_total = curr_total - lost - 1 + added
maxa = max(curr_total, maxa)
curr_start += 1
curr_end = curr_end + added
else:
while string[curr_start] != "b":
curr_start += 1
kb = k
for i in range(n):
if string[i] == "a":
kb -= 1
if kb == 0:
break
stop = False
for i in range(i + 1, n):
if string[i] != "b":
stop = True
break
i = i - stop
maxb = i + 1
curr_total = i + 1
curr_start = string.find("a")
curr_end = i
while curr_end < n - 1:
if string[curr_start] == "a":
lost = 0
i = curr_start - 1
while string[i] == "b" and i >= 0:
lost += 1
i -= 1
i = curr_end + 1
added = 0
not_changed = True
while i < n and (string[i] == "b" or not_changed):
if string[i] == "a":
not_changed = False
added += 1
i += 1
curr_total = curr_total - lost - 1 + added
maxb = max(maxb, curr_total)
curr_start += 1
curr_end = curr_end + added
else:
while string[curr_start] != "a":
curr_start += 1
print(max(maxa, maxb))
prog()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, l = input().split()
n = int(n)
l = int(l)
string = input()
a = b = x = j = 0
for i in string:
if i == "a":
a += 1
else:
b += 1
if min(a, b) > l:
if string[j] == "a":
a -= 1
else:
b -= 1
j += 1
else:
x += 1
print(x)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
a = input()
def solve(x, k):
i, j = 0, 0
ans = 0
t = k
while i < n and j < n:
while t >= 0 and j < n:
if a[j] != x and t >= 1:
t -= 1
elif a[j] != x and t == 0:
break
j += 1
ans = max([ans, j - i])
if a[i] != x:
t += 1
i += 1
return ans
print(max([solve("a", k), solve("b", k)]))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
a = 0
b = 0
left = 0
right = 0
for i in s:
if i == "a":
a = a + 1
else:
b = b + 1
if min(a, b) > k:
if s[left] == "a":
a -= 1
else:
b -= 1
left = left + 1
else:
right += 1
print(right)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = input().split(" ")
n = int(n)
k = int(k)
str = input()
def analyze(str, char):
ans = 0
count_char = 0
i = 0
j = 0
while True:
if count_char <= k:
ans = max(ans, j - i)
if count_char > k:
if str[i] == char:
count_char -= 1
i += 1
if j >= n:
break
elif count_char <= k:
j += 1
if str[j - 1] == char:
count_char += 1
if count_char <= k:
ans = max(ans, j - i)
return ans
ans = max(analyze(str, "a"), analyze(str, "b"))
print(ans)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def main():
n, k = [int(x) for x in input().split()]
s = input()
a = s[0] == "a" and 1 or 0
b = s[0] == "b" and 1 or 0
i = 0
j = 0
res = 1
while j < n - 1:
aj = 0
bj = 0
if s[j + 1] == "a":
aj += 1
else:
bj += 1
if min(a + aj, b + bj) <= k:
j += 1
a += aj
b += bj
res = max(res, j - i + 1)
else:
if s[i] == "a":
a -= 1
else:
b -= 1
i += 1
print(res)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
from sys import stdin
input = iter(stdin.readlines()).__next__
n, k = map(int, input().split())
string = input().strip()
p1a, p1b, p2 = 0, 0, 0
max_length = 0
changed_a, changed_b = 0, 0
while p2 < n:
if string[p2] == "b":
changed_a += 1
else:
changed_b += 1
if changed_a > k:
while True:
p1a += 1
if string[p1a - 1] == "b":
break
changed_a -= 1
if changed_b > k:
while True:
p1b += 1
if string[p1b - 1] == "a":
break
changed_b -= 1
p2 += 1
max_length = max(max_length, p2 - p1a, p2 - p1b)
print(max_length)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR WHILE NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR WHILE NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = list(input())
ans = 0
right = 0
cntb = 0
for left in range(n):
while cntb <= k and right < n:
if s[right] == "b":
cntb += 1
if cntb == k + 1:
cntb -= 1
break
right += 1
ans = max(ans, right - left)
if right == left:
right += 1
elif s[left] == "b":
cntb -= 1
right = 0
cnta = 0
for left in range(n):
while cnta <= k and right < n:
if s[right] == "a":
cnta += 1
if cnta == k + 1:
cnta -= 1
break
right += 1
ans = max(ans, right - left)
if right == left:
right += 1
elif s[left] == "a":
cnta -= 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def solve(k, s, c):
p = [-1, len(s)]
for i in range(len(s)):
if s[i] == c:
p += [i]
p.sort()
n = len(p)
if n - k - 1 <= 0:
return len(s)
m = 0
for i in range(n - k - 1):
m = max(m, p[i + k + 1] - p[i])
return m - 1
n, k = list(map(int, input().split()))
s = input()
print(max(solve(k, s, "a"), solve(k, s, "b")))
|
FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR STRING
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
N, T = map(int, input().split())
S = input()
a = 0
b = 0
r = 0
l = 0
mx = 0
while r < N:
if S[r] == "a":
mx = max(mx, r - l + 1)
else:
b += 1
if b <= T:
mx = max(mx, r - l + 1)
while b > T:
if S[l] == "b":
b -= 1
l += 1
r += 1
a = 0
b = 0
r = 0
l = 0
while r < N:
if S[r] == "b":
mx = max(mx, r - l + 1)
else:
a += 1
if a <= T:
mx = max(mx, r - l + 1)
while a > T:
if S[l] == "a":
a -= 1
l += 1
r += 1
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def getMax(s, i, j, t, k, n):
res = 0
count = 0
while i < n:
while j < n and count < k:
if s[j] != t:
count += 1
j += 1
while j < n and s[j] == t:
j += 1
res = max(res, j - i)
while i < n and s[i] == t:
i += 1
if i < n:
i += 1
count -= 1
return res
n, k = [int(x) for x in input().split()]
s = input()
print(max(getMax(s, 0, 0, "a", k, n), getMax(s, 0, 0, "b", k, n)))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER STRING VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER STRING VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
import sys
f = sys.stdin
n, k = map(int, f.readline().strip().split())
s = f.readline()
i = 0
j = 0
curmx = k
a = 0
b = 0
count = [0] * 26
while i < len(s):
while j < len(s) and min(a, b) <= k:
if s[j] == "a":
a += 1
else:
b += 1
j += 1
curmx = max(curmx, a + b - 1)
if j == len(s):
break
if s[i] == "a":
a -= 1
else:
b -= 1
i += 1
print(curmx)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, m = input().split(" ")
n, m = int(n), int(m)
ans = 0
s = input()
for i in range(2):
left, used = 0, 0
for right in range(n):
if ord(s[right]) != ord("a") + i:
used += 1
while used > m:
if ord(s[left]) != ord("a") + i:
used -= 1
left += 1
ans = max(ans, right - left + 1)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
def solve(s, k, target):
n = len(s)
acum = [0] * n
first = dict()
for i, v in enumerate(s):
if i > 0:
acum[i] = acum[i - 1]
if v != target:
acum[i] += 1
if acum[i] not in first:
first[acum[i]] = i
best = 0
for i in range(n):
curr = acum[i - 1] if i > 0 else 0
hi = curr + k + 1
pos = first.get(hi, n) - 1
res = pos - i + 1
best = max(best, res)
return best
n, k = map(int, input().split())
s = input()
print(max(solve(s, k, "a"), solve(s, k, "b")))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR STRING
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
a = input()
r = 0
b = [(ord(x) - ord("a")) for x in a]
s = 0
ans = 0
for i in range(n):
while r < n and (s + b[r] <= k or r + 1 - i - s - b[r] <= k):
s += b[r]
r += 1
ans = max(ans, r - i)
s -= b[i]
if r == n:
break
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
s = input()
i, j = 0, 0
ans = 0
dp = [0, 0]
while i < n:
dp[ord(s[i]) - ord("a")] += 1
if min(dp[0], dp[1]) > k:
while min(dp[0], dp[1]) > k and j <= i:
dp[ord(s[j]) - ord("a")] -= 1
j += 1
else:
ans = max(ans, dp[0] + dp[1])
i += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = list(map(int, input().split()))
s = input()
res = 0
count_a = 0
count_b = 0
left = 0
right = 0
while True:
if s[right] == "a":
count_a += 1
else:
count_b += 1
if count_a <= k or count_b <= k:
if right - left + 1 > res:
res = right - left + 1
else:
if s[left] == "a":
count_a -= 1
else:
count_b -= 1
left += 1
right += 1
if n - left < res or right == n:
break
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
n, k = map(int, input().split())
lst = input()
left = 0
right = 0
def current_length(left, right, changes_left, letter):
best_len = 0
curr_changes = changes_left
while right < n:
if curr_changes == 0 and lst[right] != letter:
if right - left > best_len:
best_len = right - left
while left < n:
if lst[left] != letter:
left += 1
break
left += 1
elif lst[right] != letter:
curr_changes -= 1
right += 1
if right - left > best_len:
best_len = right - left
return best_len
print(max(current_length(0, 0, k, "a"), current_length(0, 0, k, "b")))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR STRING FUNC_CALL VAR NUMBER NUMBER VAR STRING
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.