description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | import sys
input = []
input_index = 0
def next(type, number=None):
def next():
global input, input_index
if input_index == len(input):
if sys.stdin:
input = sys.stdin.readline().split()
input_index = 0
else:
raise Exception()
input_index += 1
return input[input_index - 1]
if number is None:
result = type(next())
else:
result = [type(next()) for _ in range(number)]
return result
n, m, q = next(int, 3)
fs = [next(int, m) for _ in range(n)]
def get_m(i):
m = 0
c = 0
for f in fs[i]:
if f:
c += 1
else:
m = max(m, c)
c = 0
m = max(m, c)
return m
ms = [get_m(i) for i in range(n)]
for _ in range(q):
i, j = next(int, 2)
i, j = i - 1, j - 1
fs[i][j] ^= 1
ms[i] = get_m(i)
print(max(ms)) | IMPORT ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF NONE FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def counting(a):
l = 0
cnt = 0
for e in a:
if e == 1:
l += 1
else:
if l > cnt:
cnt = l
l = 0
if l > cnt:
cnt = l
return cnt
def main():
n, m, q = map(int, input().split(" "))
cnt = [(0) for i in range(n)]
f = [[] for i in range(n)]
maxc = 0
for i in range(n):
f[i] = list(map(int, input().split()))
cnt[i] = counting(f[i])
if cnt[i] > maxc:
maxc = cnt[i]
for p in range(q):
i, j = map(lambda la: int(la) - 1, input().split(" "))
f[i][j] = (int(f[i][j]) + 1) % 2
cnt[i] = counting(f[i])
print(max(cnt))
main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = [int(x) for x in input().split()]
x = [([int(x) for x in input().split()] + [0]) for _ in range(n)]
s = [1, 0]
l = []
for i in range(n):
z = 0
p = 0
for j in range(m + 1):
if x[i][j] == 1:
p += 1
else:
z = max(z, p)
p = 0
l.append(z)
for _ in range(q):
a, b = [int(x) for x in input().split()]
x[a - 1][b - 1] = s[x[a - 1][b - 1]]
p = 0
z = 0
for j in range(m + 1):
if x[a - 1][j] == 1:
p += 1
else:
z = max(z, p)
p = 0
l[a - 1] = z
print(max(l)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
mat = []
for i in range(n):
mat.append([int(i) for i in input().split()])
maxr = [0] * n
for i in range(n):
j = 0
maxi = 0
while j < m:
if mat[i][j] == 1:
c = 0
while j < m and mat[i][j] == 1:
c += 1
j += 1
maxi = max(maxi, c)
else:
j += 1
maxr[i] = maxi
for i in range(q):
x, y = map(int, input().split())
x -= 1
y -= 1
mat[x][y] = 1 - mat[x][y]
maxi = 0
j = 0
while j < m:
if mat[x][j] == 1:
c = 0
while j < m and mat[x][j] == 1:
c += 1
j += 1
maxi = max(maxi, c)
else:
j += 1
maxr[x] = maxi
print(max(maxr)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def conseqones(a):
maximum = 0
index = 0
while index < len(a):
if a[index] == 1:
curcount = 1
index += 1
while index < len(a) and a[index] == 1:
index += 1
curcount += 1
if curcount > maximum:
maximum = curcount
else:
index += 1
return maximum
def findmaxrow(a):
maximum = 0
maxindex = 0
for i in range(len(a)):
cur = conseqones(a[i])
if cur > maximum:
maximum = cur
maxindex = i
return maximum, maxindex
thelist = input().split()
r = int(thelist[0])
c = int(thelist[1])
q = int(thelist[2])
a = [[(0) for i in range(c)] for j in range(r)]
for i in range(r):
therow = input().split()
for j in range(c):
a[i][j] = int(therow[j])
curmax = findmaxrow(a)[0]
curmaxindex = findmaxrow(a)[1]
for i in range(q):
coord = input().split()
x = int(coord[0]) - 1
y = int(coord[1]) - 1
a[x][y] = 1 - a[x][y]
newone = conseqones(a[x])
if newone >= curmax:
curmax = newone
curmaxindex = x
print(newone)
elif x == curmaxindex:
curmax = findmaxrow(a)[0]
curmaxindex = findmaxrow(a)[1]
print(curmax)
else:
print(curmax) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR 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 NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def getOnes(li):
ans = 0
ret = 0
for i in li:
if i == 0:
ans = 0
else:
ans += 1
ret = max(ans, ret)
return ret
rows, cols, rounds = map(int, input().split())
mat = []
scores = []
for i in range(rows):
mat.append(list(map(int, input().split())))
scores.append(getOnes(mat[i]))
for i in range(rounds):
k, b = map(int, input().split())
k -= 1
b -= 1
if mat[k][b] == 0:
mat[k][b] = 1
else:
mat[k][b] = 0
maxi = 0
scores[k] = getOnes(mat[k])
maxi = max(scores)
print(maxi) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def kadane(lst):
ans = s = 0
for n in lst:
if n == 0:
ans = max(ans, s)
s = 0
else:
s += 1
return max(ans, s)
n, m, q = map(int, input().split())
f = []
best = []
for _ in range(n):
l = list(map(int, input().split()))
f.append(l)
best.append(kadane(l))
for _ in range(q):
i, j = map(int, input().split())
f[i - 1][j - 1] = (f[i - 1][j - 1] + 1) % 2
best[i - 1] = kadane(f[i - 1])
print(max(best)) | FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def condMax(row):
flag = False
ret, cnt = 0, 0
for x in row:
if flag == False and x == 1:
cnt = 1
flag = True
elif flag == True and x == 1:
cnt += 1
elif flag == True and x == 0:
ret = max(cnt, ret)
flag = False
if flag == True:
ret = max(cnt, ret)
return ret
N, M, Q = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(N)]
rows = [condMax(row[:]) for row in board]
ans = max(rows)
for i in range(Q):
i, j = map(lambda x: int(x) - 1, input().split())
board[i][j] ^= 1
rows[i] = condMax(board[i][:])
ans = max(rows)
print(ans) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | f = lambda s: max(map(len, "".join(s).split("0")))
n, m, q = map(int, input().split())
a = [input().split() for i in range(n)]
b = list(map(f, a))
c = [list(map(int, input().split())) for i in range(q)]
for x, y in c:
a[x - 1][y - 1] = str(1 - int(a[x - 1][y - 1]))
b[x - 1] = f(a[x - 1])
print(max(b)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = list(map(int, input().split()))
g = []
for i in range(n):
g.append(list(map(int, input().split())))
ct = []
for i in range(n):
j = 0
ma = 0
while j < m:
if g[i][j] == 1:
c = 0
while g[i][j] == 1:
c = c + 1
j = j + 1
if j == m:
break
ma = max(ma, c)
else:
j = j + 1
ct.append(ma)
for k in range(q):
i, j = list(map(int, input().split()))
i, j = i - 1, j - 1
g[i][j] = 0 if g[i][j] == 1 else 1
j = 0
ma = 0
while j < m:
if g[i][j] == 1:
c = 0
while g[i][j] == 1:
c = c + 1
j = j + 1
if j == m:
break
ma = max(ma, c)
else:
j = j + 1
ct[i] = ma
print(max(ct)) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def calscore(a, r, m):
s = 0
l = 0
if [0] * m == a[r]:
return l
for i in range(len(a[r]) - 1):
if a[r][i] == 1 and a[r][i + 1] == 1:
s += 1
else:
s += 1
l = max(l, s)
s = 0
try:
if a[r][-1] == 1 and a[r][-2] == 1:
s += 1
l = max(s, l)
except:
if a[r][-1] == 1:
s += 1
l = max(s, l)
return l
n, m, q = map(int, input().split())
a = []
for i in range(n):
c = list(map(int, input().split()))
a.append(c)
scores = []
for i in range(len(a)):
scores.append(calscore(a, i, m))
p = max(scores)
for i in range(q):
x, y = map(int, input().split())
a[x - 1][y - 1] = int(not a[x - 1][y - 1])
scores[x - 1] = calscore(a, x - 1, m)
print(max(scores)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP LIST NUMBER VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
F = [list(map(int, input().split())) for i in range(n)]
def calc(i):
ans = 0
l = -1
for j in range(m):
if F[i][j] == 0:
l = j
else:
ans = max(ans, j - l)
return ans
row = list(map(calc, range(n)))
for i in range(q):
y, x = map(int, input().split())
y -= 1
x -= 1
F[y][x] = 1 - F[y][x]
row[y] = calc(y)
print(max(row)) | 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 VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | import sys
input = sys.stdin.readline
def multi_input():
return map(int, input().split())
def array_print(arr):
print(" ".join(map(str, arr)))
def findsum(arr):
ans = 0
max1 = 0
for i in arr:
if i == 1:
ans += 1
max1 = max(ans, max1)
else:
max1 = max(ans, max1)
ans = 0
return max1
n, m, q = multi_input()
matrix = []
arr = [0] * n
for i in range(n):
temp = list(multi_input())
matrix.append(temp)
arr[i] = findsum(temp)
for i in range(q):
x1, y1 = multi_input()
x1 -= 1
y1 -= 1
if matrix[x1][y1] == 0:
matrix[x1][y1] = 1
arr[x1] = findsum(matrix[x1])
elif matrix[x1][y1] == 1:
matrix[x1][y1] = 0
arr[x1] = findsum(matrix[x1])
print(max(arr)) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def main():
n, m, q = map(int, input().split())
l = [[(c == "1") for c in input()[::2]] for _ in range(n)]
def f(ro):
res = z = 0
for t in ro:
if t:
z += 1
else:
if res < z:
res = z
z = 0
if res < z:
res = z
return res
f_rows = list(map(f, l))
cnt = [0] * (m + 1)
for r in f_rows:
cnt[r] += 1
m = str(max(f_rows))
res = []
for _ in range(q):
y, x = map(int, input().split())
x -= 1
y -= 1
row, s0 = l[y], f_rows[y]
row[x] ^= True
s1 = f(row)
if s1 != s0:
f_rows[y] = s1
m = str(max(f_rows))
res.append(m)
print("\n".join(res))
main() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def get_info_current(grid, x, y, m):
dist_r = 0
hit = False
if x % m != m - 1:
for i in range(x + 1, m):
if grid[i + y * m] != 1:
dist_r = i - x - 1
hit = True
break
if not hit:
dist_r = m - x - 1
dist_l = 0
hit = False
if x % m != 0:
for i in range(x - 1, -1, -1):
if grid[i + y * m] != 1:
dist_l = x - i - 1
hit = True
break
if not hit:
dist_l = x - -1 - 1
return dist_r, dist_l
def do_simulation(grid, n, m):
max_val = 0
current_run = 0
for i in range(0, n * m):
if i % m == 0:
if current_run > max_val:
max_val = current_run
current_run = 0
if grid[i] == 1:
current_run += 1
else:
if current_run > max_val:
max_val = current_run
current_run = 0
if current_run > max_val:
max_val = current_run
return max_val
def main():
invalues = input().strip().split(" ")
n, m, q = int(invalues[0]), int(invalues[1]), int(invalues[2])
grid = [(0) for _ in range(0, n * m)]
for i in range(0, n):
row = input().strip().split(" ")
for x in range(0, m):
grid[i * m + x] = int(row[x])
max_val = do_simulation(grid, n, m)
for round in range(0, q):
invalues = input().strip().split(" ")
x, y = int(invalues[1]) - 1, int(invalues[0]) - 1
dist_r, dist_l = get_info_current(grid, x, y, m)
val = grid[x + y * m]
if val == 1:
grid[x + y * m] = 0
if dist_r + dist_l + 1 == max_val:
max_val = do_simulation(grid, n, m)
else:
grid[x + y * m] = 1
if dist_r + dist_l + 1 > max_val:
max_val = dist_r + dist_l + 1
print("{}".format(max_val))
main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | import sys
def read(line):
return [int(c) for c in line.strip().split()]
def count_row(grid, i, m):
cnt = 0 if grid[i][0] == 0 else 1
res = 0
for j in range(1, m):
cur, prev = grid[i][j], grid[i][j - 1]
if cur == 1 and prev == 1:
cnt += 1
elif cur == 0 and prev == 1:
res = max(res, cnt)
cnt = 0
elif cur == 1 and prev == 0:
cnt = 1
res = max(res, cnt)
return res
def main():
test = sys.stdin.readlines()
n, m, q = read(test[0])
grid = []
for i in range(1, n + 1):
grid.append(read(test[i]))
queries = [read(line) for line in test[n + 1 :]]
scores = [0] * n
for i in range(n):
scores[i] = count_row(grid, i, m)
for x, y in queries:
grid[x - 1][y - 1] = 1 if grid[x - 1][y - 1] == 0 else 0
scores[x - 1] = count_row(grid, x - 1, m)
print(max(scores))
main() | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
s = [input().split() for i in range(n)]
f = lambda i: max(map(len, "".join(s[i]).split("0")))
a = list(map(f, range(n)))
for i in range(q):
x, y = map(int, input().split())
x -= 1
y -= 1
s[x][y] = "1" if s[x][y] == "0" else "0"
a[x] = f(x)
print(max(a)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR STRING STRING STRING ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
ms, kk = [], []
mp = ms.append
kkp = kk.append
for i in range(n):
mp(list(map(int, input().split())))
l, mm = 0, 0
for j in range(m):
if ms[i][j]:
l += 1
else:
if l > mm:
mm = l
l = 0
if l > mm:
mm = l
kkp(mm)
for i in range(q):
y, x = map(lambda x: int(x) - 1, input().split())
mm, ms[y][x], l = 0, 1 - ms[y][x], 0
for j in range(m):
if ms[y][j]:
l += 1
else:
if l > mm:
mm = l
l = 0
if l > mm:
mm = l
kk[y] = mm
mm = 0
for ii in kk:
mm = max(mm, ii)
print(mm) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
g = [([0] * m) for i in range(0, n)]
cnt = [0] * n
for i in range(0, n):
g[i] = list(map(int, input().split()))
for i in range(0, n):
c = 0
for j in range(0, m):
if g[i][j] == 0:
if c > cnt[i]:
cnt[i] = c
c = -1
c += 1
if c > cnt[i]:
cnt[i] = c
for i in range(0, q):
r, c = map(int, input().split())
r -= 1
c -= 1
g[r][c] = not g[r][c]
cnt[r] = 0
c = 0
for j in range(0, m):
if g[r][j] == 0:
if c > cnt[r]:
cnt[r] = c
c = -1
c += 1
if c > cnt[r]:
cnt[r] = c
print(max(cnt)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | import sys
input = sys.stdin.readline
def abhi():
roe = [0] * n
for j in range(n):
ans = 0
if m == 1:
ans = max(ans, t[j][0])
else:
temp = t[j][0]
for k in range(1, m):
if t[j][k - 1] == 1 and t[j][k] == 1:
temp += 1
else:
ans = max(temp, ans)
temp = t[j][k]
ans = max(temp, ans)
roe[j] = ans
return roe
n, m, q = map(int, input().split())
t = []
for j in range(n):
t.append(list(map(int, input().split())))
row = abhi()
for j in range(q):
a, b = map(int, input().split())
a -= 1
b -= 1
t[a][b] = abs(1 - t[a][b])
ans1 = 0
mx = 0
for j in range(m):
if j == 0:
ans1 = t[a][j]
elif t[a][j] == 1:
ans1 += 1
else:
mx = max(mx, ans1)
ans1 = t[a][j]
mx = max(ans1, mx)
row[a] = mx
print(max(row)) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | string = input()
a, b, n = map(int, string.split())
rows = [list(map(int, input().split())) for x in range(a)]
def streak(y):
streaks = []
s = 0
for x in y:
if x == 0:
streaks.append(s)
s = 0
else:
s += 1
streaks.append(s)
return max(streaks)
bears = [streak(x) for x in rows]
scores = []
for x in range(n):
string = input()
numbers = string.split()
p, q = int(numbers[0]) - 1, int(numbers[1]) - 1
if rows[p][q] == 0:
rows[p][q] = 1
else:
rows[p][q] = 0
bears[p] = streak(rows[p])
scores.append(max(bears))
for x in scores:
print(x) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | r, c, g = map(int, input().split())
board = []
scores = []
for i in range(r):
board.append([int(x) for x in input().split()])
curr = 0
m = 0
for num in board[-1]:
if num == 1:
curr += 1
else:
m = max(m, curr)
curr = 0
m = max(m, curr)
scores.append(m)
for i in range(g):
x, y = map(int, input().split())
x -= 1
y -= 1
if board[x][y]:
board[x][y] = 0
else:
board[x][y] = 1
curr = 0
m = 0
for num in board[x]:
if num == 1:
curr += 1
else:
m = max(m, curr)
curr = 0
m = max(m, curr)
scores[x] = m
print(max(scores)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
l = []
for i in range(n):
l.append(list(map(int, input().split())))
count = []
for i in range(n):
c = 0
k = 0
for j in range(m):
if l[i][j] == 1:
c += 1
else:
k = max(c, k)
c = 0
k = max(c, k)
count.append(k)
for i in range(q):
a, b = map(int, input().split())
a, b = a - 1, b - 1
if l[a][b] == 0:
l[a][b] = 1
c = 0
k = 0
for j in l[a]:
if j == 1:
c += 1
else:
k = max(c, k)
c = 0
k = max(c, k)
count[a] = k
else:
l[a][b] = 0
k = 0
c = 0
for j in l[a]:
if j == 1:
c += 1
else:
k = max(c, k)
c = 0
k = max(c, k)
count[a] = k
print(max(count)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split(" "))
l = []
def maxx(l):
cmax = 0
count = 0
for i in range(len(l)):
for j in range(len(l[i])):
if l[i][j] == 1:
count += 1
if j == len(l[i]) - 1 and count > cmax:
cmax = count
else:
if count > cmax:
cmax = count
count = 0
count = 0
return cmax
def maxi(l):
c = 0
cmax = 0
for i in range(len(l)):
if l[i] == 1:
c += 1
if c > cmax:
cmax = c
else:
c = 0
return cmax
for i in range(n):
li = list(map(int, input().split(" ")))
l.append(li)
foo = []
for i in range(len(l)):
foo.append(maxi(l[i]))
for i in range(q):
i, j = map(int, input().split(" "))
l[i - 1][j - 1] = 1 - l[i - 1][j - 1]
foo[i - 1] = maxi(l[i - 1])
print(max(foo)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN 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 RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = input().split()
n = int(n)
m = int(m)
q = int(q)
l, p = [], []
def su(l):
l1 = len(l)
i = 0
hig = 0
while i < l1:
j = i
s1 = 0
while j < l1:
if l[j] == 1:
s1 += 1
else:
break
j += 1
i = j + 1
if hig < s1:
hig = s1
return hig
for i in range(n):
l1 = input().split()
for j in range(m):
l1[j] = int(l1[j])
l.append(l1)
p.append(su(l1))
for i in range(q):
x, y = input().split()
x = int(x) - 1
y = int(y) - 1
high = 0
l[x][y] = 1 - l[x][y]
p[x] = su(l[x])
for i in range(n):
if high < p[i]:
high = p[i]
print(high) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
grid = [[[None] * m] for _ in range(n)]
row_count = [0] * n
for i in range(n):
grid[i] = [int(x) for x in input().split()]
max_row = None
max_counter = 0
for i in range(n):
counter = 0
for j in range(m):
counter = counter + 1 if grid[i][j] else 0
row_count[i] = max(row_count[i], counter)
if counter > max_counter:
max_counter = counter
max_row = i
for _ in range(q):
i, j = map(int, input().split())
i -= 1
j -= 1
grid[i][j] = 0 if grid[i][j] == 1 else 1
if grid[i][j] == 1:
row_count[i] += 1
else:
row_count[i] -= 1
counter = 0
row_count[i] = 0
for k in range(m):
counter = counter + 1 if grid[i][k] else 0
row_count[i] = max(row_count[i], counter)
if row_count[i] > max_counter:
max_counter = counter
max_row = i
print(max(row_count)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NONE VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split(" "))
a = []
def cons_ones(l, m):
ans = 0
c = 0
for i in range(m):
if l[i] == 1:
c += 1
else:
ans = max(ans, c)
c = 0
ans = max(ans, c)
return ans
anss = []
for i in range(n):
s = list(map(int, input().split(" ")))
anss.append(cons_ones(s, m))
a.append(s)
for i in range(q):
x, y = map(int, input().split(" "))
x -= 1
y -= 1
if a[x][y]:
a[x][y] = 0
else:
a[x][y] = 1
anss[x] = cons_ones(a[x], m)
print(max(anss)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def solve(i):
best = 0
l = -1
for j in range(m):
if mat[i][j] == 0:
l = j
else:
best = max(best, j - l)
return best
n, m, q = map(int, input().split())
mat = [[int(j) for j in input().split()] for i in range(n)]
rows = list(map(solve, range(n)))
while q:
i, j = map(int, input().split())
i -= 1
j -= 1
mat[i][j] = 1 - mat[i][j]
rows[i] = solve(i)
print(max(rows))
q -= 1 | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def line_score(row):
m = 0
c = 0
for elem in row:
if elem == 1:
c += 1
else:
c = 0
m = max(c, m)
return m
n, m, q = [int(x) for x in input().split(" ")]
grid = [[int(x) for x in input().split(" ")] for row in range(n)]
rounds = [[int(x) for x in input().split(" ")] for round in range(q)]
z = []
for row in grid:
z.append(line_score(row))
for round in rounds:
i, j = round
grid[i - 1][j - 1] = 1 - grid[i - 1][j - 1]
z[i - 1] = line_score(grid[i - 1])
print(max(z)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
def csum(row):
return max(map(len, row.split("0")))
grid = ["".join(input().split()) for i in range(n)]
score = [max(map(len, row.split("0"))) for row in grid]
for i in range(q):
i, j = map(int, input().split())
row = grid[i - 1]
row = row[: j - 1] + ("1" if row[j - 1] == "0" else "0") + row[j:]
grid[i - 1] = row
score[i - 1] = csum(row)
print(max(score)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING STRING STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def fff(i):
nonlocal a
nonlocal m
t = 0
max = 0
for j in range(m + 1):
if a[i][j] == 0:
if t > max:
max = t
t = 0
else:
t = t + 1
return max
n, m, q = list(map(int, input().split()))
a = []
s = []
for i in range(0, n):
w = list(map(int, input().split()))
w.append(0)
a.append(w)
s.append(fff(i))
for i in range(q):
x, y = list(map(int, input().split()))
a[x - 1][y - 1] = (a[x - 1][y - 1] + 1) % 2
s[x - 1] = fff(x - 1)
print(max(s)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def su(grid):
ans, l = 0, 0
for v in grid:
if v == 1:
l += 1
else:
l = 0
ans = max(l, ans)
return ans
n, m, q = map(int, input().split(" "))
grid = []
for i in range(n):
grid.append(list(map(int, input().split())))
s = list(map(su, grid))
for _ in range(q):
i, j = map(int, input().split(" "))
i, j = i - 1, j - 1
if grid[i][j] == 0:
s[i] += 1
else:
s[i] -= 1
grid[i][j] = 1 - grid[i][j]
s[i] = su(grid[i])
print(max(s)) | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | n, m, q = map(int, input().split())
arr = []
ans = [0] * n
for j in range(n):
s = list(map(int, input().split()))
maxx = 0
cnt = 1
if len(s) == 1:
ans[j] = s[0]
else:
for i in range(m):
if i < m - 1 and s[i] == s[i + 1] and s[i] == 1:
cnt += 1
else:
maxx = max(cnt, maxx)
cnt = 1
ans[j] = maxx
arr.append(s)
for j in range(q):
a, b = map(int, input().split())
a -= 1
b -= 1
arr[a][b] = arr[a][b] ^ 1
s = arr[a]
if len(s) == 1:
ans[a] = s[0]
else:
maxx = 0
cnt = 1
for i in range(m):
if i < m - 1 and s[i] == s[i + 1] and s[i] == 1:
cnt += 1
else:
maxx = max(cnt, maxx)
cnt = 1
ans[a] = maxx
print(max(ans)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def count_max(start, finish):
mx = 0
pos = 0
for i in range(start, finish):
s = "".join(a[i])
s = s.split("0")
for j in s:
l = len(j)
if l > mx:
mx = l
pos = i
return mx, pos
def count(c, d):
v = 0
t = d
while t != -1 and a[c][t] == "1":
v += 1
t -= 1
t = d
while t != m and a[c][t] == "1":
v += 1
t += 1
if a[c][d] == "1":
v -= 1
return v
n, m, q = map(int, input().split())
a = []
for i in range(n):
a.append(input().split())
mx, pos = count_max(0, n)
for i in range(q):
c, d = map(int, input().split())
c -= 1
d -= 1
a[c][d] = str(1 - int(a[c][d]))
if c == pos:
mx, pos = count_max(0, n)
else:
v = count(c, d)
if v > mx:
mx = v
pos = c
print(mx) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image]
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
-----Input-----
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
-----Output-----
After each round, print the current score of the bears.
-----Examples-----
Input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
Output
3
4
3
3
4 | def get_row_score(row):
max_score = 0
current_score = int(row[0])
last = row[0]
for e in row[1:]:
if e:
if current_score == 0:
current_score = 1
if e == last:
current_score += 1
else:
max_score = max(max_score, current_score)
current_score = 0
last = e
return max(max_score, current_score)
n, m, q = map(int, input().split())
grid = []
row_scores = [0] * n
for i in range(n):
row = list(map(bool, map(int, input().split())))
row_scores[i] = get_row_score(row)
grid.append(row)
for _ in range(q):
i, j = map(int, input().split())
i -= 1
j -= 1
grid[i][j] = not grid[i][j]
row_scores[i] = get_row_score(grid[i])
print(max(row_scores)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
s = input()
a = list(map(int, input().split()))
MOD = 10**9 + 7
INF = float("inf")
dp = [([0] * 3) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n + 1):
dp[i][2] = INF
dp[0][2] = 0
num = 0
for i in range(n):
li = INF
for j in range(i + 1, n + 1):
k = ord(s[j - 1]) - ord("a")
li = min(li, a[k])
if j - i > li:
break
else:
dp[j][0] += dp[i][0]
dp[j][0] %= MOD
dp[j][1] = max(dp[j][1], max(dp[i][1], j - i))
dp[j][2] = min(dp[j][2], dp[i][2] + 1)
print(dp[n][0])
print(dp[n][1])
print(dp[n][2]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | def ri():
return map(int, input().split())
n = int(input())
s = input()
s = [(ord(x) - ord("a")) for x in s]
a = list(ri())
T = [(0) for i in range(n)]
maxs = 0
mins = 0
lasts = 0
for i in range(len(s)):
if i == 0:
maxs = 1
T[i] = 1
mins += 1
continue
mm = i
smin = 10**9
for j in range(i, max(i - a[s[i]], -1), -1):
length = i - j + 1
flag = 0
smin = min(a[s[j]], smin)
if smin < length:
break
else:
mm = j
if j == 0:
adding = 1
else:
adding = T[j - 1]
T[i] += adding
T[i] = T[i] % (10**9 + 7)
maxs = max(maxs, i - mm + 1)
if mm > lasts:
mins += 1
lasts = i
print(T[n - 1])
print(maxs)
print(mins) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | read = lambda: map(int, input().split())
n = int(input())
s = input()
a = list(read())
dp = [0] * (n + 2)
mn = [10**4] * (n + 2)
dp[0] = dp[n + 1] = 1
mn[n + 1] = 0
mn[0] = 1
Max = 1
mod = 10**9 + 7
for i in range(1, n):
res = 0
cur = 10**4
for j in range(i, -1, -1):
c = ord(s[j]) - ord("a")
cur = min(cur, a[c])
if cur < i - j + 1:
break
dp[i] = (dp[i] + dp[j - 1]) % mod
mn[i] = min(mn[i], mn[j - 1] + 1)
Max = max(Max, i - j + 1)
print(dp[n - 1])
print(Max)
print(mn[n - 1]) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | from sys import stdin, stdout
n = int(stdin.readline())
s = stdin.readline().strip()
length = list(map(int, stdin.readline().strip().split()))
bn = [(2**i) for i in range(10**3 + 2)]
dp = [(0) for i in range(n + 10)]
dp[0] = 1
dp[-1] = 1
ans = [0, 1, 0]
dp1 = [(0) for i in range(n + 5)]
dp1[0] = 1
for i in range(1, n):
label = 1
cnt = min(i + 1, length[ord(s[i]) - ord("a")])
while label:
label = 0
for ind in range(i - cnt + 1, i + 1):
if length[ord(s[ind]) - ord("a")] < cnt:
cnt -= 1
label = 1
break
dp1[i] = dp1[i - cnt] + 1
ans[1] = max(ans[1], cnt)
if cnt == i + 1:
dp[i] = bn[cnt - 1]
else:
for j in range(1, cnt + 1):
dp[i] += dp[i - j]
ans[0] = dp[n - 1] % (10**9 + 7)
ans[2] = dp1[n - 1]
stdout.write("\n".join(list(map(str, ans)))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
s = input()
alf = list(map(int, input().split()))
d = [(0) for i in range(n + 1)]
div = int(10**9 + 7)
d[0] = 1
maxlen = -1
a = ord("a")
INF = int(10**10)
md = [INF for i in range(n + 1)]
md[0] = 0
for i in range(1, n + 1):
l = alf[ord(s[i - 1]) - a]
minlen = l
for j in range(l):
if i - j < 1:
break
minlen = min(minlen, alf[ord(s[i - j - 1]) - a])
if minlen < j + 1:
break
maxlen = max(maxlen, j + 1)
d[i] += d[i - j - 1] % div
d[i] %= div
md[i] = min(md[i], 1 + md[i - j - 1])
print(d[n])
print(maxlen)
print(md[n]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | N, s, l = (
int(input()),
[(ord(x) - ord("a")) for x in input()],
[int(x) for x in input().split()],
)
arr = [[1, l[s[0]]]]
total = 1
ma = 1
t = 1
mi = 1
for c in s[1:]:
tmp = 0
for i in range(len(arr)):
arr[i][1] = min(arr[i][1], l[c])
if i + 1 >= arr[i][1]:
arr = arr[:i]
if t > i:
t = 0
mi += 1
break
else:
tmp += arr[i][0]
t += 1
arr.insert(0, [total, l[c]])
ma = max(ma, len(arr))
total += tmp
total %= 10**9 + 7
print(total)
print(ma)
print(mi) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | M = 1000000007
n = int(input())
s = input()
a = list(map(int, input().split()))
ans2 = 0
dp = [0] * n + [1]
for i in range(n):
maxlen = 9001
for j in range(1, i + 2):
maxlen = min(maxlen, a[ord(s[i - j + 1]) - ord("a")])
if maxlen >= j:
dp[i] = (dp[i] + dp[i - j]) % M
else:
break
ans2 = max(ans2, j)
print(dp[n - 1])
print(ans2)
ans3 = 1
acc = 0
maxlen = 9001
for i in range(n):
acc += 1
maxlen = min(maxlen, a[ord(s[i]) - ord("a")])
if acc > maxlen:
acc = 1
ans3 += 1
maxlen = a[ord(s[i]) - ord("a")]
print(ans3) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
s = input()
ai = list(map(int, input().split()))
a = ord("a")
e = 10**9 + 7
dp = [1] + [0] * n
dp2 = [0] * (n + 1)
l = 0
for i in range(1, n + 1):
dp2[i] = n
f = i - 1
ma = 10000
while f >= 0:
ma = min(ma, ai[ord(s[f]) - a])
if ma < i - f:
break
dp[i] = (dp[i] + dp[f]) % e
dp2[i] = min(dp2[i], dp2[f] + 1)
l = max(l, i - f)
f -= 1
print(dp[n], l, dp2[n], sep="\n") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
s = input()
t = tuple(map(int, input().split()))
dp = [1]
maxi = 0
for i in range(n):
ca = 0
ma = 0
if i == 0:
ca += dp[0]
ma += 1
else:
cl = 0
cp = i
m = t[ord(s[i]) - 97]
while cl < m and cp >= 0:
ca += dp[cp]
cl += 1
m = min(m, t[ord(s[cp - 1]) - 97])
cp -= 1
ma += 1
if ma > maxi:
maxi = ma
dp.append(ca)
print(dp[-1] % 1000000007)
print(maxi)
i = 0
count = 0
cl = 1
while i < n:
m = t[ord(s[i]) - 97]
cp = i + 1
count += 1
while cl < m and cp < n:
m = min(m, t[ord(s[cp]) - 97])
if cl < m:
cl += 1
cp += 1
else:
break
i = i + cl
cl = 1
cp = i
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
s = input()
S = [(ord(znak) - 97) for znak in s]
a = list(map(int, input().strip().split(" ")))
MOD = 10**9 + 7
st = [0] * (n + 1)
st[0] = 1
maks = [0] * (n + 1)
minway = [10**4] * (n + 1)
minway[0] = 0
for i in range(1, n + 1):
cnt = 0
maks_dolzina = n
for j in range(i, 0, -1):
maks_dolzina = min(maks_dolzina, a[S[j - 1]])
if i - j + 1 > maks_dolzina:
break
cnt += st[j - 1]
maks[i] = max(i - j + 1, maks[j - 1], maks[i])
minway[i] = min(minway[i], 1 + minway[j - 1])
st[i] = cnt
print(st[-1] % MOD)
print(maks[-1])
print(minway[-1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | import sys
mod = 10**9 + 7
n = int(input())
s = input()
cnt = list(map(int, input().split()))
dp = [0]
for i in range(0, n):
dp.append(0)
dp[0] = 1
ans2 = 1
for i in range(1, n + 1):
o = i - 1
ml = cnt[ord(s[o]) - ord("a")]
l = 1
while ml >= l and o >= 0:
dp[i] += dp[o]
dp[i] = dp[i] % mod
if l > ans2:
ans2 = l
l += 1
o -= 1
ml = min(ml, cnt[ord(s[o]) - ord("a")])
ans1 = dp[n] % mod
ans3 = 0
ml = n
l = 0
for i in range(n):
ml = min(ml, cnt[ord(s[i]) - ord("a")])
l += 1
if l > ml:
ans3 += 1
l = 1
ml = cnt[ord(s[i]) - ord("a")]
ans3 += 1
print(ans1)
print(ans2)
print(ans3) | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | MOD = 1000000007
n = int(input())
s = input()
a = list(map(int, input().split()))
dp = [1]
dp_min = [0]
max_len = 1
for i in range(0, n):
len = 1
dp.append(dp[-1])
dp_min.append(dp_min[-1] + 1)
min_let = a[ord(s[i]) - ord("a")]
while i - len >= 0 and len < min_let:
min_let = min(min_let, a[ord(s[i - len]) - ord("a")])
if len < min_let:
dp[-1] = (dp[-1] + dp[i - len]) % MOD
dp_min[-1] = min(dp_min[-1], dp_min[i - len] + 1)
max_len = max(len + 1, max_len)
len += 1
print(dp[-1] % MOD)
print(max_len)
print(dp_min[-1]) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING WHILE BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
st = input()
a = list(map(int, input().split()))
list = [[] for i in range(n)]
arr = []
for i in range(n):
arr.append(a[ord(st[i]) - 97])
ans3 = 0
add = 0
flag = 0
for i in range(n):
mini = arr[i]
count = 1
j = i
while count <= mini and j < n:
list[i].append(j)
j += 1
count += 1
if j < n:
mini = min(mini, arr[j])
if i == ans3 and flag == 0:
add += 1
ans3 = j
if j == n:
flag = 1
counted = [(0) for i in range(n)]
for i in list[0]:
counted[i] = 1
ans2 = len(list[0])
i = 0
while i < n - 1:
total = counted[i]
ans2 = max(ans2, len(list[i]))
for j in list[i + 1]:
counted[j] += total
i += 1
ans2 = max(ans2, len(list[i]))
print(counted[n - 1] % (10**9 + 7))
print(ans2)
print(add) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | mod = 10**9 + 7
n = int(input())
s = input()
l = list(map(int, input().split()))
dp = [0] * (n + 1)
dp1 = [0] * (n + 1)
dp[n] = 1
ans2 = 0
ans3 = 0
for i in range(n - 1, -1, -1):
e = [0] * 26
for j in range(i, n):
e[ord(s[j]) - 97] = 1
flag = 1
for b in range(26):
if e[b] and l[b] < j - i + 1:
flag = 0
break
if flag:
ans2 = max(ans2, j - i + 1)
if dp1[i] == 0:
dp1[i] = 1 + dp1[j + 1]
else:
dp1[i] = min(dp1[i], 1 + dp1[j + 1])
dp[i] = (dp[i] + dp[j + 1]) % mod
else:
break
print(dp[0])
print(ans2)
print(dp1[0]) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | def getMap(str):
characters = "abcdefghijklmnopqrstuvwxyz"
countMap = {}
for i in characters:
countMap[i] = 0
arrCountMap = []
for i in str:
countMap[i] += 1
arrCountMap.append(countMap)
return arrCountMap
def getCharIndex():
characters = "abcdefghijklmnopqrstuvwxyz"
index = {}
count = 0
for i in characters:
index[i] = count
count += 1
return index
n = int(input())
str = input()
input_a = input()
if n == 1:
print(1)
print(1)
print(1)
quit()
a = list(map(int, input_a.split(" ")))
dp = []
for i in range(n + 10):
dp.append(0)
dp[0] = 1
arrCountMap = getMap(str)
mod = 1000000000.0 + 7
maxLen = 0
charIndex = getCharIndex()
for j in range(1, len(str)):
i = j - 1
charSet = set()
charSet.add(str[j])
while i >= -1:
allowed = True
for char in charSet:
if a[charIndex[char]] < j - i:
allowed = False
break
if not allowed:
break
maxLen = max(maxLen, j - i)
if i == -1:
dp[j] = int((dp[j] + 1) % mod)
break
else:
dp[j] = int((dp[j] + dp[i]) % mod)
charSet.add(str[i])
i -= 1
count = 1
subStringLen = 0
charSet.clear()
for i in range(len(str)):
newSubstring = False
charSet.add(str[i])
subStringLen += 1
for char in charSet:
if a[charIndex[char]] < subStringLen:
newSubstring = True
break
if newSubstring:
count += 1
charSet.clear()
charSet.add(str[i])
subStringLen = 1
print(int(dp[n - 1] % mod))
print(maxLen)
print(count) | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | M = 10**9 + 7
def o(i):
return ord(s[i]) - 97
n = int(input())
s = input()
a = [int(item) for item in input().split()]
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
mn = float("inf")
longest = -float("inf")
maxNb = 1
ii = 1
tmp = a[o(0)]
if a[o(0)] == 1 and n != 1:
maxNb += 1
tmp = float("inf")
ii = 0
if n == 1:
longest = 1
for i in range(2, n + 1):
ii += 1
j = 0
mn = a[o(i - 1)]
k = -1
while j <= i and j <= mn:
mn = min(mn, a[o(i - j - 1)])
dp[i] += dp[i - j] % M
j += 1
k += 1
dp[i] %= M
longest = max(longest, k)
tmp = min(tmp, a[o(i - 1)])
if i == n:
break
if tmp == ii:
ii = 0
tmp = float("inf")
maxNb += 1
elif tmp < ii:
ii = 1
maxNb += 1
tmp = a[o(i - 1)]
if i == n - 1:
maxNb += 1
elif i == n - 1:
if a[o(i)] < ii + 1:
maxNb += 1
print(dp[n] % M)
print(longest)
print(maxNb) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | import sys
mod = pow(10, 9) + 7
n = int(sys.stdin.readline())
s = sys.stdin.readline()[:-1]
a = [int(x) for x in sys.stdin.readline().split()]
dp = [(0) for _ in range(n + 1)]
dp[0] = 1
def ci(c):
return ord(c) - ord("a")
l = 0
for i in range(1, n + 1):
f = 0
for x in range(i - 1, -1, -1):
f = max(f, i - a[ci(s[x])])
if f > x:
continue
dp[i] = (dp[i] + dp[x]) % mod
l = max(l, i - x)
print(dp[n])
print(l)
res = 1
m = 9999
j = 0
for i in range(n):
m = min([a[ci(s[x])] for x in range(j, i + 1)])
if m < i - j + 1:
res += 1
j = i
print(res) | IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | MOD = int(1000000000.0) + 7
n = int(input())
s = input()
a = list(map(int, input().split()))
dp = [0] * (n + 2)
dp[0], dp[n + 1] = 1, 1
mn = [int(10000.0)] * (n + 2)
mn[0], mn[n + 1] = 1, 0
res = 1
for i in range(1, n):
cur = int(10000.0)
for j in range(i, -1, -1):
c = ord(s[j]) - ord("a")
cur = min(cur, a[c])
if cur < i - j + 1:
break
dp[i] = (dp[i] + dp[j - 1]) % MOD
mn[i] = min(mn[i], mn[j - 1] + 1)
res = max(res, i - j + 1)
print(dp[n - 1])
print(res)
print(mn[n - 1]) | ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | import sys
mod = 10**9 + 7
inf = 1 << 30
def solve():
n = int(input())
msg = input()
clim = [int(i) for i in input().split()]
dp = [0] * (n + 1)
dp[0] = 1
max_len = 0
for i in range(1, n + 1):
limlen = inf
cur_len = 0
for j in range(i, 0, -1):
alpha = ord(msg[j - 1]) - ord("a")
limlen = min(limlen, clim[alpha])
cur_len += 1
if cur_len > limlen:
break
max_len = max(max_len, cur_len)
dp[i] = (dp[i] + dp[j - 1]) % mod
min_sp = 0
cur_len = 0
limlen = inf
for ch in msg:
cur_len += 1
alpha = ord(ch) - ord("a")
limlen = min(limlen, clim[alpha])
if cur_len > limlen:
cur_len = 1
min_sp += 1
limlen = clim[alpha]
print(dp[n])
print(max_len)
print(min_sp + 1)
solve() | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
d = [0] * (n + 1)
way = [n] * (n + 1)
s = "0" + input()
m = list(map(int, input().split()))
d[1] = 1
d[0] = 1
way[0] = 0
way[1] = 1
dic = dict()
dic["0"] = 1000
i = 0
for l in "abcdefghijklmnopqrstuvwxyz":
dic[l] = m[i]
i += 1
high = 1
big = 10**9 + 7
for i in range(2, n + 1):
z = i - 1
x = i - dic[s[i]]
while z >= 0 and x <= z:
x = max(x, i - dic[s[z]])
high = max(high, i - z)
d[i] += d[z]
way[i] = way[z] + 1
z -= 1
d[i] = d[i] % big
z += 1
if not z:
high = i
print(d[-1])
print(high)
print(way[-1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR STRING ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than a_{i}. For example, if a_1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a_1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions: How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 10^9 + 7. What is the maximum length of a substring that can appear in some valid splitting? What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^3) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a_1, a_2, ..., a_26 (1 ≤ a_{x} ≤ 10^3) — the maximum lengths of substring each letter can appear in.
-----Output-----
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 10^9 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
-----Examples-----
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
-----Note-----
In the first example the three ways to split the message are: a|a|b aa|b a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a_1 = 2. | n = int(input())
s = list(input())
abc = "abcdefghijklmnopqrstuvwxyz"
limit = list(map(int, input().split()))
mod = int(1000000000.0) + 7
memo = [None] * n
def main():
num_ways, longest, min_num = split(0)
print(num_ways)
print(longest)
print(min_num)
def split(start):
if start >= len(s):
return 1, 0, 0
if memo[start] is not None:
return memo[start]
num_ways = 0
longest = 0
min_num = 100000.0
max_allowed = 100000.0
for i in range(start, len(s)):
current_length = i - start + 1
max_allowed = min(max_allowed, limit[abc.find(s[i])])
if current_length > max_allowed:
break
longest = max(current_length, longest)
ss_num_ways, ss_longest, ss_min_num = split(i + 1)
num_ways = (num_ways + ss_num_ways) % mod
longest = max(longest, ss_longest)
min_num = min(min_num, ss_min_num + 1)
memo[start] = num_ways, longest, min_num
return memo[start]
def __starting_point():
main()
__starting_point() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER NUMBER NUMBER IF VAR VAR NONE RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def solve(n, c, a, b):
res = c
money = 0
days = 0
for i in range(n):
res = min(res, days + (c - money + a[i] - 1) // a[i])
if i + 1 < n:
extra_days = (max(b[i] - money, 0) + a[i] - 1) // a[i]
money += a[i] * extra_days
money -= b[i]
assert money >= 0
days += extra_days
days += 1
return res
t = int(input())
for _ in range(t):
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, c, a, b)) | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def solve():
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cur_money = 0
cur_days = 0
ans = int(1000000000000.0)
for i in range(n):
need_to_buy = c - cur_money
ans = min(ans, cur_days + (need_to_buy + a[i] - 1) // a[i])
if i < n - 1:
need_to_upgrade = b[i] - cur_money
if need_to_upgrade <= 0:
cur_days += 1
cur_money -= b[i]
else:
cur_days += (need_to_upgrade + a[i] - 1) // a[i]
cur_days += 1
cur_money = (need_to_upgrade + a[i] - 1) // a[i] * a[
i
] - need_to_upgrade
print(ans)
for _ in range(int(input())):
solve() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def ceil(a, b):
return (a + b - 1) // b
def calculateMin(a, b):
days = 0
money = 0
ans = float("inf")
for i in range(n - 1):
ans = min(ans, ceil(c - money, a[i]) + days)
toReachNext = ceil(b[i] - money, a[i])
days += 1 + toReachNext
money += a[i] * toReachNext - b[i]
ans = min(ans, ceil(c - money, a[-1]) + days)
return ans
for _ in range(int(input())):
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(calculateMin(a, b)) | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | I = lambda: [*map(int, input().split())]
def out(x):
print(str(x))
def solve():
n, c = I()
a = I()
b = I()
best_d = 1000000009
current_m = 0
current_d = 0
for i in range(n):
wait = int((c - current_m + a[i] - 1) / a[i])
best_d = min(best_d, wait + current_d)
if i == n - 1:
continue
new_days = int(max(0, b[i] - current_m + a[i] - 1) / a[i])
current_m += new_days * a[i]
current_m -= b[i]
current_d += new_days + 1
out(best_d)
(t,) = I()
for i in range(t):
solve() | ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | for _ in range(int(input())):
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
money = 0
ans = 0
arr = []
arr.append((c + a[0] - 1) // a[0])
for i in range(1, n):
cnt = (b[i - 1] + a[i - 1] - 1 - money) // a[i - 1] + 1
ans += cnt
money += (cnt - 1) * a[i - 1] - b[i - 1]
arr.append(ans + (c - money + a[i] - 1) // a[i])
print(min(arr)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)
def main():
ntc = next(ints)
for tc in range(1, ntc + 1):
n, c = (next(ints) for i in range(2))
a = [next(ints) for i in range(n)]
b = [next(ints) for i in range(n - 1)]
def ceil(num, den):
return (num + den - 1) // den
i = 0
m = 0
days = 0
ans = float("inf")
while 1:
ans = min(ans, days + ceil(c - m, a[i]))
if i == n - 1:
break
k = ceil(max(0, b[i] - m), a[i])
m += a[i] * k - b[i]
assert m >= 0
days += k + 1
i += 1
print(ans)
return
main() | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | for i in range(int(input())):
n, c = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = 0
x = 0
d1 = -1
for i in range(n):
d2 = d + max(0, -((x - c) // a[i]))
if d1 == -1 or d2 < d1:
d1 = d2
if i != n - 1:
d += max(0, -((x - b[i]) // a[i])) + 1
x = x + max(0, -((x - b[i]) // a[i])) * a[i] - b[i]
print(d1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def solve(n, c, a, b):
ds = [-1] * n
s = 0
d = 0
ds[0] = -(-c // a[0])
for i in range(n - 1):
if s >= b[i]:
s -= b[i]
d += 1
else:
dd = -(-(b[i] - s) // a[i])
d += dd + 1
s += dd * a[i] - b[i]
ds[i + 1] = d + (-(-(c - s) // a[i + 1]) if c > s else 0)
2 + 2
print(min(ds))
t = int(input())
for _ in range(t):
n, c = map(int, input().split())
(*a,) = map(int, input().split())
(*b,) = map(int, input().split())
solve(n, c, a, b) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def debug(*args):
pass
for _ in range(int(input())):
n, c = map(int, input().split())
(*salaries,) = map(int, input().split())
(*prices,) = map(int, input().split())
days_to_reach = [0]
rem = [0]
balance = 0
for i in range(n - 1):
days = (prices[i] - balance + salaries[i] - 1) // salaries[i]
balance += days * salaries[i] - prices[i]
rem.append(balance)
days_to_reach.append(days + 1)
cum_days_to_reach = days_to_reach.copy()
for i in range(n - 1):
cum_days_to_reach[i + 1] += cum_days_to_reach[i]
ans = (c + salaries[0] - 1) // salaries[0]
debug("rem", rem)
debug("days_to_reach", days_to_reach)
debug("cum_days", cum_days_to_reach)
debug(ans)
for i in range(1, n):
new_ans = cum_days_to_reach[i] + (c - rem[i] + salaries[i] - 1) // salaries[i]
if new_ans < ans:
ans = new_ans
debug(i, "is better", new_ans)
print(ans) | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | for __ in range(int(input())):
n, c = list(map(int, input().split()))
ar1 = list(map(int, input().split()))
ar2 = list(map(int, input().split()))
kevukeka = c
ans = 10**9
days_gone = 0
money2_1 = 0
for i in range(n - 1):
days1 = (c + ar1[i] - 1) // ar1[i] + days_gone
days2_1 = (ar2[i] - money2_1 + ar1[i] - 1) // ar1[i]
money2_1 += ar1[i] * days2_1 - ar2[i]
c = kevukeka - money2_1
days_gone += days2_1 + 1
ans = min(ans, days1)
days1 = (c + ar1[n - 1] - 1) // ar1[n - 1] + days_gone
ans = min(ans, days1)
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | t = int(input())
for _ in range(t):
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
day, left = [0] * (n + 1), [0] * (n + 1)
now = 0
for i in range(n - 1):
mx = a[i]
if b[i] <= now:
day[i + 1] = day[i] + 1
now -= b[i]
else:
cost = (b[i] - now + a[i] - 1) // a[i]
day[i + 1] = day[i] + cost + 1
now = now + cost * a[i] - b[i]
left[i + 1] = now
l, r = 1, 10**9
while l <= r:
mid = (l + r) // 2
def ok(mid):
for i in range(n):
if day[i] > mid:
break
if (mid - day[i]) * a[i] + left[i] >= c:
return True
return False
if ok(mid):
r = mid - 1
else:
l = mid + 1
print(l) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
ans = float("inf")
n, c = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
nhave = 0
nday = 0
for i in range(n):
plusday = max(0, (c - nhave + a[i] - 1) // a[i])
ans = min(ans, nday + plusday + i)
if i == n - 1:
break
plusday = max(0, (b[i] - nhave + a[i] - 1) // a[i])
nhave = nhave + plusday * a[i] - b[i]
nday += plusday
print(ans) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
l = input().split()
n = int(l[0])
c = int(l[1])
l = input().split()
li = [int(i) for i in l]
b = input().split()
bi = [int(i) for i in b]
bi.append(0)
days = 0
extra = 0
maxa = 10**18
for i in range(n):
req = c - extra
if req < 0:
continue
maxa = min(maxa, days + (req + li[i] - 1) // li[i])
if bi[i] <= extra:
nod = 1
else:
nod = 1 + (bi[i] - extra + li[i] - 1) // li[i]
days += nod
extra += (nod - 1) * li[i]
extra -= bi[i]
print(maxa) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | t = int(input())
for _ in range(t):
n, c = [int(num) for num in input().strip().split(" ")]
pos = [int(num) for num in input().strip().split(" ")]
move = [int(num) for num in input().strip().split(" ")]
res = int(1000000000000.0)
x = 0
d = 0
for i in range(n - 1):
a = pos[i]
res = min(d + max(c - x, 0) // a + int(max(c - x, 0) % a != 0), res)
d += max(move[i] - x, 0) // a + int(max(move[i] - x, 0) % a != 0) + 1
x = (
x
+ a * (max(move[i] - x, 0) // a + int(max(move[i] - x, 0) % a != 0))
- move[i]
)
res = min(
d + max(c - x, 0) // pos[n - 1] + int(max(c - x, 0) % pos[n - 1] != 0), res
)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def ceil(a, b):
if a % b:
return a // b + 1
else:
return a // b
for testis in range(int(input())):
n, c = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 10**20
curr = 0
time = 0
for i in range(n):
cans = ceil(c - curr, a[i])
ans = min(ans, time + cans)
if i != n - 1:
time_for_next_pos = ceil(b[i] - curr, a[i])
curr = curr + (a[i] * time_for_next_pos - b[i])
time += time_for_next_pos + 1
print(ans) | FUNC_DEF IF BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | for _ in range(int(input())):
n, c = map(int, input().split())
arrA = list(map(int, input().split()))
arrB = list(map(int, input().split()))
daysToPos = 0
curBal = 0
ans = float("inf")
for pos in range(n):
if curBal >= c:
ans = min(ans, daysToPos)
break
else:
ans = min(
ans,
daysToPos
+ (c - curBal) // arrA[pos]
+ (1 if (c - curBal) % arrA[pos] else 0),
)
if pos < n - 1:
if arrB[pos] >= c:
break
if curBal >= arrB[pos]:
daysToPos += 1
curBal -= arrB[pos]
else:
daysToNext = (arrB[pos] - curBal) // arrA[pos] + (
1 if (arrB[pos] - curBal) % arrA[pos] else 0
)
daysToPos += daysToNext + 1
curBal += daysToNext * arrA[pos] - arrB[pos]
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
input = sys.stdin.readline
cas = int(input())
while cas:
cas -= 1
n, c = map(int, input().split())
d = [[0, 0] for i in range(n)]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tmp = 0
for i in range(1, n):
tt = (b[i - 1] - tmp + a[i - 1] - 1) // a[i - 1]
d[i][0] = d[i - 1][0] + tt + 1
d[i][1] = tmp + a[i - 1] * tt - b[i - 1]
tmp = d[i][1]
ans = 20**9
for i in range(n):
ans = min(ans, d[i][0] + (c - d[i][1] + a[i] - 1) // a[i])
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | for _ in range(int(input())):
n, c = map(int, input().split())
a, b = list(map(int, input().split())), list(map(int, input().split())) + [0]
balance = 0
cur = 0
ans = 10**18 + 1
for i in range(n):
ans = min(ans, cur + max(0, c - balance + a[i] - 1) // a[i])
new = max(0, b[i] - balance + a[i] - 1) // a[i]
cur += new + 1
balance += a[i] * new - b[i]
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
input = sys.stdin.readline
for CASES in range(int(input())):
n, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 10**9
last = 0
now = 0
top = 0
i = 0
while top != n - 1:
if last >= B[top]:
last -= B[top]
top += 1
i += 1
delta = c - last
addi = (delta + A[top] - 1) // A[top]
ans = min(ans, i + addi)
if top == n - 1:
break
i += (B[top] - last + A[top] - 1) // A[top]
last += (B[top] - last + A[top] - 1) // A[top] * A[top]
print(ans) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
input = sys.stdin.readline
def solve():
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [None] * n
dp[0] = 0, 0
ans = max((c + a[0] - 1) // a[0], 0)
for i in range(1, n):
d, h = dp[i - 1]
s = a[i - 1]
dn = max((b[i - 1] - h + s - 1) // s, 0)
h += s * dn - b[i - 1]
d += dn + 1
dp[i] = d, h
dn = max((c - h + a[i] - 1) // a[i], 0)
ans = min(ans, d + dn)
print(ans)
for i in range(int(input())):
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def solve():
n, c = input_as_list()
a = input_as_list()
b = input_as_list()
ans = float("inf")
coins, time = 0, 0
for i in range(n):
ans = min(ans, time + ceil_div(c - coins, a[i]))
if i < n - 1:
days = ceil_div(b[i] - coins, a[i])
time += days + 1
coins += days * a[i] - b[i]
print(ans)
def ceil_div(a, b):
return max(0, (a + b - 1) // b)
def input_as_list():
return [int(t) for t in input().split()]
for _ in range(int(input())):
solve() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
max_int = 10**18
def ceil(p, q):
return (p - 1) // q + 1
t = int(input())
for _t in range(t):
n, c = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split())) + [0]
for i in range(1, len(a)):
a[i] = max(a[i], a[i - 1])
out = max_int
d = 0
cash = 0
for i in range(len(a)):
out = min(out, d + max(0, ceil(c - cash, a[i])))
days_to_up = max(ceil(b[i] - cash, a[i]), 0)
d += days_to_up + 1
cash = cash - b[i] + days_to_up * a[i]
print(out) | IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
def main():
t = int(input())
allans = []
for _ in range(t):
n, computerCost = readIntArr()
a = readIntArr()
b = readIntArr()
c = [None for _ in range(n)]
d = [None for _ in range(n)]
money = 0
day = 0
c[0] = 0
d[0] = 0
for i in range(n - 1):
toEarn = max(0, b[i] - money)
nDays = (toEarn + a[i] - 1) // a[i]
day += nDays
money += nDays * a[i] - b[i]
day += 1
c[i + 1] = day
d[i + 1] = money
assert money >= 0
earliestDay = inf
for i in range(n):
day = c[i]
money = d[i]
toEarn = max(0, computerCost - money)
additionalDays = (toEarn + a[i] - 1) // a[i]
earliestDay = min(earliestDay, day + additionalDays)
allans.append(earliestDay)
multiLineArrayPrint(allans)
return
input = sys.stdin.buffer.readline
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultVal, dimensionArr):
dv = defaultVal
da = dimensionArr
if len(da) == 1:
return [dv for _ in range(da[0])]
else:
return [makeArr(dv, da[1:]) for _ in range(da[0])]
def queryInteractive(x, y):
print("? {} {}".format(x, y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(ans))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | from sys import stdin
readline = stdin.readline
def readInt():
return int(readline())
def readInts():
return list(map(int, readline().split()))
t = readInt()
for i in range(t):
n, c = readInts()
a_list = readInts()
b_list = readInts()
days_to_reach = [(0, 0)]
days_to_finish = []
for i in range(0, n - 1):
days_curr, money_curr = days_to_reach[i]
if money_curr >= b_list[i]:
days_to_reach.append((days_curr + 1, money_curr - b_list[i]))
else:
days_work = (b_list[i] - money_curr + a_list[i] - 1) // a_list[i]
remaining = money_curr + days_work * a_list[i] - b_list[i]
days_to_reach.append((days_curr + days_work + 1, remaining))
for i in range(0, n):
days_curr, money_curr = days_to_reach[i]
if money_curr >= c:
days_to_finish.append(days_curr)
else:
days_finish = (c - money_curr + a_list[i] - 1) // a_list[i]
days_to_finish.append(days_curr + days_finish)
print(min(days_to_finish)) | ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def cl(a, b):
return a // b + int(bool(a % b))
for _ in range(int(input())):
n, c = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
b = [int(x) for x in input().split(" ")]
assert len(a) == n and len(b) == n - 1
dp = [None] * n
res = [None] * n
dp[0] = 0
res[0] = 0
for i in range(1, n):
x = cl(max(0, b[i - 1] - res[i - 1]), a[i - 1])
dp[i] = dp[i - 1] + x + 1
res[i] = res[i - 1] - b[i - 1] + x * a[i - 1]
assert res[i] >= 0
ans = dp[0] + cl(max(0, c - res[0]), a[0])
for i in range(n):
ans = min(ans, dp[i] + cl(max(0, c - res[i]), a[i]))
print(ans) | FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | times = int(input())
while times > 0:
times -= 1
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
now = 0
ans = (c + a[0] - 1) // a[0]
for i in range(1, n):
if now >= c:
break
t = (b[i - 1] - now + a[i - 1] - 1) // a[i - 1]
now += t * a[i - 1] - b[i - 1]
cnt += t + 1
tmp = (c - now + a[i] - 1) // a[i] + cnt
ans = min(ans, tmp)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | for nt in range(int(input())):
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = (c - 1) // a[0] + 1
d = (b[0] - 1) // a[0] + 1
p = d * a[0]
for i in range(1, n):
p -= b[i - 1]
d += 1
ans = min(ans, d + (c - p - 1) // a[i] + 1)
if i == n - 1:
break
d += (b[i] - p - 1) // a[i] + 1
p += ((b[i] - p - 1) // a[i] + 1) * a[i]
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def helper(a, b, c):
pool = [0] * len(a)
pool[0] = (c - 1) // a[0] + 1
d = 0
m = 0
for i in range(1, len(a)):
d += (b[i - 1] - m - 1) // a[i - 1] + 1 + 1
m = (m - b[i - 1]) % a[i - 1]
tc = c - m
pool[i] = d + (tc - 1) // a[i] + 1
return min(pool)
t = int(input())
for i in range(t):
n, c = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
print(helper(a, b, c)) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | from sys import stdin
def ii():
return int(stdin.readline())
def fi():
return float(stdin.readline())
def mi():
return map(int, stdin.readline().split())
def fmi():
return map(float, stdin.readline().split())
def li():
return list(mi())
def si():
return stdin.readline().rstrip()
def lsi():
return list(si())
t = ii()
while t > 0:
n, st = mi()
a = li()
b = li()
ans = 10**9 * 2
cur_days = 0
cur_pos = 0
cur_money = 0
while cur_pos < n - 1:
ans = min(
ans,
cur_days
+ max(st - cur_money, 0) // a[cur_pos]
+ (1 if max(st - cur_money, 0) % a[cur_pos] != 0 else 0),
)
need_days = max(b[cur_pos] - cur_money, 0) // a[cur_pos] + (
1 if max(b[cur_pos] - cur_money, 0) % a[cur_pos] != 0 else 0
)
left_money = cur_money + a[cur_pos] * need_days - b[cur_pos]
cur_days += need_days + 1
cur_money = left_money
cur_pos += 1
ans = min(
ans,
cur_days
+ max(st - cur_money, 0) // a[cur_pos]
+ (1 if max(st - cur_money, 0) % a[cur_pos] != 0 else 0),
)
print(ans)
t -= 1 | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, c = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
temp = [int(x) for x in input().split()]
curr, days, ans = 0, 0, sys.maxsize
for i in range(n):
ans = min(ans, days + (c - curr + arr[i] - 1) // arr[i])
if i != n - 1:
now = (temp[i] - curr + arr[i] - 1) // arr[i]
days += now + 1
curr = curr + now * arr[i] - temp[i]
print(ans) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def solve():
lst = input().split()
n = int(lst[0])
c = int(lst[1])
a = list(map(lambda x: int(x), input().split()))
b = list(map(lambda x: int(x), input().split()))
mint = [0] * n
extr = [0] * n
for i in range(0, n - 1):
delned = b[i] - extr[i]
tiempo = (delned + a[i] - 1) // a[i]
delned -= tiempo * a[i]
mint[i + 1] = mint[i] + tiempo + 1
extr[i + 1] = -delned
minn = -1
for i in range(n):
aans = (c - extr[i] + a[i] - 1) // a[i]
if minn == -1:
minn = aans
minn = min(minn, aans + mint[i])
print(minn)
caso = int(input())
while caso > 0:
caso -= 1
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
input = sys.stdin.readline
output = sys.stdout.write
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
def ceil(n, d):
if n % d == 0:
return n // d
else:
return 1 + n // d
def main():
t = inp()
for i in range(0, t):
[n, c] = inlt()
solve(n, c, inlt(), inlt())
def req_days(arv_asset, earn, cost):
rem = max(0, cost - arv_asset)
return ceil(rem, earn)
def solve(n, c, a, b):
arv_day = [(0) for i in range(0, n)]
arv_asset = [(0) for i in range(0, n)]
for i in range(0, n - 1):
clct_days = ceil(max(0, b[i] - arv_asset[i]), a[i])
arv_day[i + 1] = arv_day[i] + clct_days + 1
arv_asset[i + 1] = arv_asset[i] + clct_days * a[i] - b[i]
min_days = req_days(0, a[0], c)
for i in range(1, n):
min_days = min(min_days, arv_day[i] + req_days(arv_asset[i], a[i], c))
output("{}\n".format(min_days))
main() | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP NUMBER BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN LIST VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def ceil(x, y):
if x <= 0:
return 0
return (x + y - 1) // y
def solve():
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
rem = 0
su = 0
ans = ceil(c, a[0])
for i, v in enumerate(a[: n - 1]):
d = ceil(b[i] - rem, v)
su += d + 1
rem += d * v - b[i]
ans = min(ans, su + ceil(c - rem, a[i + 1]))
print(ans)
def main():
t = 1
t = int(input())
for _ in range(t):
solve()
main() | FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
def main():
tc = int(input())
for _ in range(tc):
solve()
def solve():
n, c = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()] + [0]
cur_amount = 0
cur = 0
ans = sys.maxsize
for i in range(0, n):
ans = min(ans, cur + max(0, c - cur_amount + a[i] - 1) // a[i])
new_days = max(0, b[i] - cur_amount + a[i] - 1) // a[i]
cur += new_days + 1
cur_amount += a[i] * new_days - b[i]
print(ans)
main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | t = int(input())
while t > 0:
t -= 1
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 1234567890
total = 0
current = 0
for i in range(n):
ans = min(ans, total + max((c - current + a[i] - 1) // a[i], 0))
if i < n - 1:
q = (b[i] - current + a[i] - 1) // a[i]
q = max(q, 0)
total += q + 1
current = current + a[i] * q - b[i]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | def solve(A, B, n, c):
days = 0
wallet = 0
ans = float("inf")
for job in range(n):
wage = A[job]
left = max(c - wallet, 0)
tim = (left + wage - 1) // wage
ans = min(ans, days + tim)
if job == n - 1:
break
course_fee = B[job]
left = max(course_fee - wallet, 0)
tim = (left + wage - 1) // wage
days += tim + 1
wallet += wage * tim - course_fee
return ans
for case in range(int(input())):
n, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = solve(A, B, n, c)
print(ans) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
input = sys.stdin.readline
ceil = lambda x, y: (x + y - 1) // y
t = int(input())
for _ in range(t):
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = ceil(c, a[0])
switch = [0]
balance = [0]
for i in range(1, n):
switch.append(1 + switch[i - 1] + ceil(b[i - 1] - balance[i - 1], a[i - 1]))
balance.append(
balance[i - 1] + (switch[i] - switch[i - 1] - 1) * a[i - 1] - b[i - 1]
)
ans = min(ans, switch[i] + ceil(c - balance[i], a[i]))
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.
There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.
Each day Polycarp can do one of two things:
If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.
If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.
For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:
On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;
On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;
On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;
On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;
On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;
On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;
Six days later, Polycarp can buy himself a new computer.
Find the minimum number of days after which Polycarp will be able to buy himself a new computer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.
The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).
The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.
-----Examples-----
Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000
-----Note-----
None | import sys
def input():
return sys.stdin.readline().rstrip()
def ceil(x, y):
return (x + y - 1) // y
def slv():
n, c = map(int, input().split())
salary = list(map(int, input().split()))[::-1]
promotion_cost = list(map(int, input().split()))[::-1]
ans = 1 << 128
left_money = 0
prev_day = 0
for finish_post in range(n):
earning = salary.pop()
if left_money < c:
more_need_day = ceil(c - left_money, earning)
ans = min(ans, prev_day + more_need_day)
if finish_post < n - 1:
prom_cost = promotion_cost.pop()
more_need_day_for_promote = 0
if left_money < prom_cost:
more_need_day_for_promote = ceil(prom_cost - left_money, earning)
left_money = (
earning * more_need_day_for_promote + left_money - prom_cost
)
prev_day += more_need_day_for_promote
prev_day += 1
else:
more_need_day_for_promote = 0
left_money -= prom_cost
prev_day += more_need_day_for_promote
prev_day += 1
else:
ans = min(ans, prev_day)
break
print(ans)
return
def main():
t = int(input())
for i in range(t):
slv()
return
main() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR |
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.
Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely: the first basket will contain $3$ red and $1$ blue berries from the first shrub; the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
-----Input-----
The first line contains two integers $n$ and $k$ ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.
The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.
-----Output-----
Output one integer — the maximum number of baskets that Phoenix can fill completely.
-----Examples-----
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
-----Note-----
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind. | def check(k, aas, bs, a_rem, b_rem):
if a_rem + b_rem < k:
return False
a_lo = k - b_rem
a_hi = a_rem
rems = set()
rems.add(0)
for a, b in zip(aas, bs):
if a + b < k:
continue
for i in range(max(0, k - b), min(a, k) + 1):
rem = i % k
for j in list(rems):
rems.add((j + rem) % k)
for rem in rems:
if rem >= a_lo and rem <= a_hi:
return True
return False
n, k = [int(x) for x in input().split()]
aas = []
bs = []
a_total = 0
b_total = 0
for i in range(n):
a, b = [int(x) for x in input().split()]
aas.append(a)
bs.append(b)
a_total += a
b_total += b
ans = a_total // k + b_total // k
if check(k, aas, bs, a_total % k, b_total % k):
print(ans + 1)
else:
print(ans) | FUNC_DEF IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.
Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely: the first basket will contain $3$ red and $1$ blue berries from the first shrub; the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
-----Input-----
The first line contains two integers $n$ and $k$ ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.
The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.
-----Output-----
Output one integer — the maximum number of baskets that Phoenix can fill completely.
-----Examples-----
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
-----Note-----
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind. | import sys
readline = sys.stdin.readline
def merge(A, B):
res = A[:]
for i in range(len(A)):
if A[i]:
for j in range(len(B)):
if B[j]:
res[(i + j) % K] = 1
return res
N, K = map(int, readline().split())
R = 0
B = 0
flag = False
table = [0] * K
table[0] = 1
for _ in range(N):
r, b = map(int, readline().split())
R += r
B += b
if r >= K and b >= K:
flag = True
elif r + b >= K:
st, en = max(0, K - b), min(K, r)
t2 = [0] * K
for i in range(st, en + 1):
t2[i % K] = 1
table = merge(table, t2)
if flag:
print((R + B) // K)
elif R // K + B // K == (R + B) // K:
print((R + B) // K)
else:
pr = R % K
pb = B % K
ans = R // K + B // K
for i in range(K):
if table[i]:
if (pr - i) % K + (pb - K + i) % K < K:
ans += 1
break
print(ans) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.
Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely: the first basket will contain $3$ red and $1$ blue berries from the first shrub; the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
-----Input-----
The first line contains two integers $n$ and $k$ ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.
The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.
-----Output-----
Output one integer — the maximum number of baskets that Phoenix can fill completely.
-----Examples-----
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
-----Note-----
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind. | n, k = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
a[i], b[i] = map(int, input().split())
base = sum(a) // k + sum(b) // k
A = sum(a) % k
B = sum(b) % k
data = [(False) for i in range(k)]
for i in range(n):
ndata = [data[j] for j in range(k)]
for j in range(1, k):
if j <= a[i] and k - j <= b[i]:
ndata[j] = True
for x in range(1, k):
prev = (x - j) % k
if data[prev]:
ndata[x] = True
data = ndata
check = False
for i in range(1, k):
if i <= A and k - i <= B:
if data[i]:
check = True
print(base + check) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.
Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely: the first basket will contain $3$ red and $1$ blue berries from the first shrub; the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
-----Input-----
The first line contains two integers $n$ and $k$ ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.
The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.
-----Output-----
Output one integer — the maximum number of baskets that Phoenix can fill completely.
-----Examples-----
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
-----Note-----
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind. | n, k = map(int, input().split())
totA = 0
totB = 0
A = [0]
B = [0]
dp = []
for i in range(n + 1):
h = []
for j in range(k):
h.append(False)
dp.append(h)
dp[0][0] = True
for i in range(n):
a, b = map(int, input().split())
A.append(a)
B.append(b)
totA += a
totB += b
for i in range(1, n + 1):
for j in range(k):
dp[i][j] = dp[i - 1][(j - A[i] % k + k) % k]
for l in range(0, min(k - 1, A[i])):
if (A[i] - l) % k + B[i] >= k:
dp[i][j] |= dp[i - 1][(j - l) % k]
ans = 0
for i in range(k):
if dp[n][i]:
ans = max(ans, (totA + totB - i) // k)
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.
Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely: the first basket will contain $3$ red and $1$ blue berries from the first shrub; the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
-----Input-----
The first line contains two integers $n$ and $k$ ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.
The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.
-----Output-----
Output one integer — the maximum number of baskets that Phoenix can fill completely.
-----Examples-----
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
-----Note-----
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind. | import itertools as it
n, k = map(int, input().split())
bushes = [tuple(map(int, input().split())) for i in range(n)]
red = sum(bush[0] for bush in bushes)
blue = sum(bush[1] for bush in bushes)
r0 = red % k
r1 = blue % k
max_ = (red + blue) // k
if r0 + r1 < k:
print(max_)
exit()
r0_required = set(range(r0 + r1 - k + 1))
r0_available = {r0}
for red, blue in bushes:
if red + blue < k:
continue
max_red = min(k - 1, red)
min_red = max(0, k - blue)
for ex_r, diff in it.product(list(r0_available), range(min_red, max_red + 1)):
new_r = ex_r - diff
if new_r < 0:
new_r += k
if new_r in r0_required:
print(max_)
exit()
r0_available.add(new_r)
print(max_ - 1) | 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 VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.
Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely: the first basket will contain $3$ red and $1$ blue berries from the first shrub; the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
-----Input-----
The first line contains two integers $n$ and $k$ ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.
The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.
-----Output-----
Output one integer — the maximum number of baskets that Phoenix can fill completely.
-----Examples-----
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
-----Note-----
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind. | import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
n, k = MI()
ab = LLI(n)
pre = 1
sa = sb = 0
mask = (1 << k) - 1
for a, b in ab:
sa += a
sb += b
if a + b < k:
continue
mn = max(k - b, 0)
mx = min(a, k - 1)
now = pre
for s in range(mn, mx + 1):
now |= pre << s
now |= now >> k
now &= mask
pre = now
ans = 0
for r in range(k):
if pre >> r & 1:
ans = max(ans, (sa - r) // k + (sb + r) // k)
print(ans)
main() | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.