description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
T = 3010
a = [[] for i in range(T)]
for i in range(n):
x, y = map(int, input().split())
a[x].append([y, 1])
ans = 0
for i in range(T):
a[i] = a[i][::-1]
j = 0
cur = v
while j < len(a[i]):
if a[i][j][0] > cur:
ans += cur
if a[i][j][1] == 0:
j += 1
else:
a[i][j][0] -= cur
break
else:
ans += a[i][j][0]
cur -= a[i][j][0]
j += 1
for t in range(j, len(a[i])):
if a[i][t][1] != 0:
a[i + 1].append([a[i][t][0], 0])
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER LIST VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
frukti_po_dnyam = {}
n, resurs = map(int, input().split(" "))
for i in range(n):
den, chislo_fruktov = map(int, input().split(" "))
if den in frukti_po_dnyam:
frukti_po_dnyam[den] += chislo_fruktov
else:
frukti_po_dnyam[den] = chislo_fruktov
if den + 1 not in frukti_po_dnyam:
frukti_po_dnyam[den + 1] = 0
def ubir(chislo, vichet):
tmp = chislo - vichet
if tmp < 0:
return 0, -tmp
return tmp, 0
vsego = 0
for i in sorted(frukti_po_dnyam):
ostatok = resurs
if i - 1 in frukti_po_dnyam:
frukti_po_dnyam[i - 1], ostatok = ubir(frukti_po_dnyam[i - 1], ostatok)
frukti_po_dnyam[i], ostatok = ubir(frukti_po_dnyam[i], ostatok)
vsego += resurs - ostatok
print(vsego)
|
ASSIGN VAR DICT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER VAR RETURN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
g = [(0) for x in range(3002)]
for i in range(n):
a, b = map(int, input().split())
g[a] += b
r = 0
for i in range(1, 3002):
c = v
r += min(c, max(g[i - 1], 0))
c -= max(g[i - 1], 0)
if c > 0:
r += min(c, g[i])
g[i] = max(g[i] - c, 0)
print(r)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
def read(mode=2):
inputs = input().strip()
if mode == 0:
return inputs
if mode == 1:
return inputs.split()
if mode == 2:
return [int(x) for x in inputs.split()]
def write(s="\n"):
if isinstance(s, list):
s = " ".join(s)
s = str(s)
print(s, end="")
n, v = read()
a = []
for i in range(n):
a.append(read())
a.sort(key=lambda x: x[0])
res = 0
for day in range(1, 3002):
n = 0
while a and a[0][0] <= day:
if a[0][1] <= v - n:
n += a[0][1]
a[0][1] = 0
else:
a[0][1] -= v - n
n = v
if a[0][1] == 0:
a.pop(0)
else:
break
while a and a[0][0] == day - 1:
a.pop(0)
res += n
print(res)
|
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR IF VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
N = [(0) for i in range(3002)]
for i in range(n):
x, y = map(int, input().split())
N[x] += y
cost = 0
cur = 0
for i in range(3002):
if N[i] + cur > v:
cost += v
if cur > v:
cur = N[i]
else:
cur = N[i] - (v - cur)
else:
cost += N[i] + cur
cur = 0
print(cost)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
def main():
R = lambda: map(int, input().split())
n, v = R()
mlist = [0] * 3003
for i in range(n):
a, b = R()
mlist[a] += b
mlist2 = mlist[:]
ans = 0
for i in range(1, 3002):
tmp = min(v, mlist[i])
ans += tmp
mlist[i + 1] += min(mlist[i] - tmp, mlist2[i])
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
arr = [0] * 3002
for _ in range(n):
a, b = map(int, input().split())
arr[a] += b
x = v
ans = 0
prev = 0
for i in range(1, 3002):
x = max(x - prev, 0)
ans += v - x
if arr[i] <= x:
ans += arr[i]
prev = 0
else:
ans += x
prev = arr[i] - x
x = v
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
l = lambda: map(int, input().split())
n, v = l()
t = {}
for _ in " " * n:
x, y = l()
t[x] = t.get(x, 0) + y
s = 0
for i in range(min(t), max(t) + 2):
us = v
x = min(us, t.get(i - 1, 0))
s += x
us -= x
t[i - 1] = t.get(i - 1, 0) - x
x = min(us, t.get(i, 0))
s += x
t[i] = t.get(i, 0) - x
print(s)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR BIN_OP STRING VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, m = map(int, input().split())
d = {}
for i in range(n):
a, b = map(int, input().split())
d[a] = d.get(a, 0) + b
d = {x: d[x] for x in sorted(d)}
p = -1
r = 0
out = 0
for x in d:
if x - p > 1:
r = 0
p = x
f = min(d[x], m * 2 - r)
r = max(min(m, d[x] - m + r), 0)
out += f
print(out)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, V = map(int, input().split())
A = []
max_no_of_days = 0
for _ in range(n):
a, b = map(int, input().split())
A.append([a, b])
max_no_of_days = max(max_no_of_days, a)
A.sort()
Fruits = [0] * (max_no_of_days + 2)
for i in A:
Fruits[i[0]] += i[1]
S = 0
for i in range(1, max_no_of_days + 2):
v = V
if Fruits[i - 1]:
y = min(Fruits[i - 1], v)
S += y
v -= y
x = min(Fruits[i], v)
S += x
v -= x
Fruits[i] -= x
print(S)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = list(map(int, input().split()))
trees = {}
days = set()
for i in range(n):
a, b = list(map(int, input().split()))
if a not in trees:
trees[a] = b
else:
trees[a] += b
days.add(a)
max_days = max(days)
total = 0
for a in range(1, max_days + 1):
prev_collected = 0
if a - 1 in trees:
prev_collected = min(trees[a - 1], v)
trees[a - 1] -= prev_collected
total += prev_collected
if a in trees:
collected = min(trees[a], v - prev_collected)
trees[a] -= collected
total += collected
elif a - 1 in trees and prev_collected == 0:
add_collected = min(trees[a - 1], v)
trees[a - 1] -= add_collected
total += add_collected
if max_days in trees:
total += min(trees[max_days], v)
print(total)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
a = [0] * 3002
ans = 0
for i in range(n):
y, x = map(int, input().split())
a[y] += x
for i in range(1, 3002):
usable = v
z = min(usable, a[i - 1])
ans += z
usable -= z
a[i - 1] -= z
z = min(usable, a[i])
ans += z
usable -= z
a[i] -= z
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
DEBUG = False
n, v = [int(x) for x in input().split()]
fruits = []
for i in range(n):
aa, bb = [int(x) for x in input().split()]
fruits.append([aa, bb])
fruits.sort()
day, t_harvested, tot, curr = 0, 0, 0, []
def remove_old():
while fruits != [] and fruits[0][0] < day - 1:
t = fruits.pop(0)
if DEBUG:
print("Rotten {} on day {}".format(t, day))
while curr != [] and curr[0][0] < day - 1:
curr.pop(0)
def add_current():
for f in fruits:
if day - 1 <= f[0] <= day:
curr.append(f)
if DEBUG:
print("New fruit {} on day {}".format(f, day))
def harvest_todays():
global t_harvested
global tot
while curr != []:
t = curr.pop(0)
harvest = min(t[1], v - t_harvested)
if DEBUG:
print("Harvested {} of {} on day {}".format(harvest, t, day))
t_harvested += harvest
t[1] -= harvest
tot += harvest
while fruits != []:
remove_old()
add_current()
harvest_todays()
day += 1
t_harvested = 0
print(tot)
|
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER LIST FUNC_DEF WHILE VAR LIST VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR WHILE VAR LIST VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_DEF WHILE VAR LIST ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR WHILE VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
s, t = 0, [0] * 3002
for i in range(n):
a, b = map(int, input().split())
t[a] += b
for d in range(1, 3002):
ds = min(t[d - 1], v)
s += ds
ds = min(t[d], v - ds)
t[d] -= ds
s += ds
print(s)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
total_plucked = 0
n, v = list(map(int, input().split()))
fruits = [0] * 3002
plucked = [0] * 30002
for _ in range(n):
a, b = list(map(int, input().split()))
fruits[a] = fruits[a] + b
for i in range(1, 3002):
plucked[i] = fruits[i - 1] if fruits[i - 1] <= v else v
if plucked[i] < v:
pluck = fruits[i] if fruits[i] <= v - plucked[i] else v - plucked[i]
plucked[i] += pluck
fruits[i] -= pluck
total_plucked += plucked[i]
print(total_plucked)
|
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER 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 BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
f = [0] * 3005
for i in range(n):
a, b = map(int, input().split())
f[a] += b
day = 1
down = 0
collect = 0
while day <= 3001:
curr = f[day]
if curr + down <= v:
collect += curr + down
curr = 0
else:
collect += v
if down < v:
curr = curr + down - v
day += 1
down = curr
print(collect)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
f = list()
for i in range(n):
f.append(list(map(int, input().split())))
f.sort()
sum = 0
today = 0
tomor = 0
day = 0
rest = 0
for tree in f:
if tree[0] > day + 1:
sum += min(tomor, v)
tomor = tree[1]
sum += min(tomor, v)
rest = v - min(tomor, v)
tomor -= min(tomor, v)
day = tree[0]
elif tree[0] == day + 1:
sum += min(tomor, v)
rest = v - min(tomor, v)
tomor = tree[1]
t = min(tomor, rest)
sum += t
rest -= t
tomor -= t
day = tree[0]
else:
tomor += tree[1]
t = min(tomor, rest)
sum += t
rest -= t
tomor -= t
sum += min(tomor, v)
print(sum)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split(" "))
result, day, trees = 0, 1, {}
for i in range(n):
days, fruits = map(int, input().split(" "))
if days in trees:
trees[days] += fruits
else:
trees[days] = fruits
while day <= 3001:
to_collect = v
if day - 1 in trees:
x = trees[day - 1]
trees[day - 1] = max(0, trees[day - 1] - v)
to_collect = max(0, v - x)
result += v - to_collect
if day in trees:
f = to_collect
t = trees[day]
trees[day] = max(0, trees[day] - to_collect)
to_collect = max(0, to_collect - t)
result += f - to_collect
day += 1
print(result)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split(" "))
a, b = [], []
for i in range(n):
x, y = map(int, input().split(" "))
a.append(x)
b.append(y)
fi = max(a)
li = []
for i in range(fi + 3):
li.append([0, 0])
for i in range(n):
li[a[i]][1] += b[i]
ans = 0
for i in range(fi + 2):
if li[i][0] <= v:
ans += li[i][0]
if li[i][1] <= v - li[i][0]:
ans += li[i][1]
else:
ans += v - li[i][0]
li[i + 1][0] = li[i][1] - v + li[i][0]
else:
ans += v
li[i + 1][0] = li[i][1]
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
import itertools as it
import sys
class pair:
x, y = 0, 0
array = [pair() for _ in range(4000)]
n, v = map(int, input().split())
for _ in range(n):
a, b = map(int, input().split())
array[a].y += b
array[a + 1].x += b
ans = 0
for i in range(1, 3500):
tmp = v
ans += min(tmp, array[i].x)
tmp -= min(tmp, array[i].x)
ans += min(tmp, array[i].y)
array[i + 1].x -= min(tmp, array[i].y)
print(ans)
|
IMPORT IMPORT CLASS_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
import sys
f = sys.stdin
n, v = map(int, f.readline().strip().split())
p = [0] * 3002
for i in range(n):
a, b = map(int, f.readline().strip().split())
p[a] += b
S = 0
for k in range(1, len(p)):
dv = min(v, p[k - 1])
S += dv
p[k - 1] -= dv
dv = min(v - dv, p[k])
S += dv
p[k] -= dv
print(S)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
trees = [0] * 3002
for i in range(n):
a, b = map(int, input().split())
trees[a] += b
ans = 0
prev = 0
for i in range(1, len(trees)):
available = min(v, prev + trees[i])
ans += available
if prev >= v:
prev = trees[i]
else:
prev = max(0, trees[i] - (v - prev))
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
trees = [list(map(int, input().split())) for i in range(n)]
trees.sort()
mergedTrees = []
treeIndex = 0
currentDay = trees[treeIndex][0]
while treeIndex < len(trees):
nbFruits = 0
while treeIndex < len(trees) and trees[treeIndex][0] == currentDay:
nbFruits += trees[treeIndex][1]
treeIndex += 1
mergedTrees.append([currentDay, nbFruits])
if treeIndex < len(trees):
currentDay = trees[treeIndex][0]
collected = 0
for treeIndex, tree in enumerate(mergedTrees):
used = 0
if treeIndex >= 1:
lastTree = mergedTrees[treeIndex - 1]
if lastTree[0] == tree[0] - 1:
used = min(v, lastTree[1])
collected += min(v, lastTree[1])
nextUsed = min(tree[1], v - used)
collected += nextUsed
tree[1] -= nextUsed
if len(mergedTrees) > 0:
lastTree = mergedTrees[len(mergedTrees) - 1]
collected += min(v, lastTree[1])
print(collected)
|
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 EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
import sys
sys.setrecursionlimit(100000)
n, v = [int(x) for x in sys.stdin.readline().strip().split()]
arr = [0] * 3002
k = [0]
for i in range(n):
a, b = [int(x) for x in sys.stdin.readline().strip().split()]
if arr[a] == 0:
k.append(a)
arr[a] += b
k.sort()
count = 0
for i in k[1:]:
if arr[i + 1] != 0:
c = v
al = min(c, arr[i - 1])
count += al
arr[i - 1] -= al
c = c - min(c, al)
count += min(c, arr[i])
arr[i] -= min(c, arr[i])
else:
c = v
al = min(c, arr[i - 1])
count += al
arr[i - 1] -= al
c = c - min(c, al)
count += min(c, arr[i])
arr[i] -= min(c, arr[i])
c = v
count += min(c, arr[i])
arr[i] -= min(c, arr[i])
print(count)
|
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
lst = [0] * 4001
for _ in range(n):
a, b = map(int, input().split())
lst[a] += b
b = lst[:]
t = 0
for day in range(4000):
x = min(v, b[day])
t += x
b[day + 1] += min(b[day] - x, lst[day])
print(t)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
def main():
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
a1, b1 = map(int, input().split())
a.append(a1)
b.append(b1)
prev = 0
tv = 0
ans = 0
for i in range(1, 3002):
curr = 0
for j in range(n):
if a[j] == i:
curr += b[j]
if curr + prev <= m:
ans += prev + curr
prev = 0
else:
ans += m
tv = m - prev
if tv < 0:
tv = 0
prev = curr - tv
print(ans)
return
main()
|
FUNC_DEF ASSIGN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
total, limit = map(int, input().split())
l = [int(0)] * 3002
due = [int(0)] * 3002
ans = int(0)
for i in range(total):
day, mango = map(int, input().split())
l[day - 1] += mango
for i in range(3002):
tut = limit
if due[i] <= tut:
ans += due[i]
tut -= due[i]
else:
ans += tut
tut = 0
if l[i] <= tut:
ans += l[i]
tut -= l[i]
else:
ans += tut
due[i + 1] = l[i] - tut
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
a = []
for x in range(n):
p = list(map(int, input().split()))
a.append((p[0], p[1]))
a.sort()
arr = [0] * 4000
for x in range(n):
arr[a[x][0]] += a[x][1]
tmp = max(0, arr[a[x][0]] - v)
arr[a[x][0]] -= tmp
arr[a[x][0] + 1] += tmp
arr[a[x][0] + 1] = min(arr[a[x][0] + 1], v)
print(sum(arr))
|
ASSIGN 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 NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
apples = [0] * 3002
for i in range(n):
a, b = map(int, input().split())
apples[a] += b
count = 0
for i in range(1, 3002):
leftover = apples[i - 1]
collectable = min(v, apples[i] + leftover)
count += collectable
apples[i] = apples[i] + min(0, leftover - collectable)
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().rstrip().split())
li = [0] * 3002
t = 0
for i in range(n):
a, b = map(int, input().rstrip().split())
li[a] += b
for i in range(1, 3002):
x = min(v, li[i - 1])
y = min(li[i], v - x)
li[i - 1] -= x
li[i] -= y
t += x + y
print(t)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
l = []
for j in range(3001):
l += [0]
for k in range(n):
x, y = map(int, input().split())
l[x - 1] += y
sum = 0
for kl in range(3001):
if kl == 0:
if v <= l[kl]:
sum += v
l[kl] -= v
else:
sum += l[kl]
l[kl] = 0
else:
v1 = v
if v1 <= l[kl - 1]:
sum += v1
l[kl - 1] -= v1
else:
sum += l[kl - 1]
v1 -= l[kl - 1]
l[kl - 1] = 0
if v1 > 0:
if v1 <= l[kl]:
sum += v1
l[kl] -= v1
else:
sum += l[kl]
l[kl] = 0
print(sum)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
def read_integer_pair():
line = input()
pair = line.split(" ")
assert len(pair) == 2
return int(pair[0]), int(pair[1])
n, v = read_integer_pair()
trees = {}
for i in range(n):
a, b = read_integer_pair()
if a in trees:
trees[a] += b
else:
trees[a] = b
trees = list(trees.items())
trees.sort(key=lambda x: x[0])
prev_a = 0
prev_b = 0
apples = 0
for a, b in trees:
dv = min(v, prev_b)
apples += dv
if a - prev_a != 1:
dv = 0
dv = max(min(v - dv, b), 0)
apples += dv
prev_a = a
prev_b = b - dv
dv = min(v, prev_b)
apples += dv
print(apples)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, k = map(int, input().split(" "))
dict = {}
max = []
for i in range(n):
a, b = map(int, input().split(" "))
if a in dict:
dict[a] += b
else:
dict[a] = b
for i in dict.copy():
if i + 1 not in dict:
dict[i + 1] = 0
def summa_fruit(dict):
k = dict.values()
sum = 0
for i in k:
sum += i
return sum
def max_kol_fruit(dict, k):
l = summa_fruit(dict)
for i in sorted(dict):
if i - 1 in dict:
if dict[i - 1] >= k:
dict[i - 1] = dict[i - 1] - k
elif dict[i - 1] < k and dict[i] + dict[i - 1] >= k:
dict[i] = dict[i] - k + dict[i - 1]
dict[i - 1] = 0
else:
dict[i - 1] = 0
dict[i] = 0
elif dict[i] >= k:
dict[i] = dict[i] - k
else:
dict[i] = 0
return l - summa_fruit(dict)
print(max_kol_fruit(dict, k))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
t = []
for i in range(n):
t.append(list(map(int, input().split())))
t.sort()
c = 0
a = 0
for d in range(3002):
l = 0
while c < n and t[c][0] < d - 1:
c += 1
while l < v and c < n and t[c][0] <= d:
if t[c][0] == d or t[c][0] == d - 1:
if t[c][1] <= v - l:
l += t[c][1]
t[c][1] = 0
else:
t[c][1] -= v - l
l = v
if t[c][1] == 0:
c += 1
a += l
if c >= n:
break
print(a)
|
ASSIGN 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
inp = []
for i in range(n):
x, y = map(int, input().split())
e = [x, y]
inp.append(e)
inp = sorted(inp)
b = []
a = []
for e in inp:
a.append(e[0])
b.append(e[1])
cur = 0
day = 1
ans = 0
while day <= a[-1] + 1:
while day > a[cur] + 1 and cur + 1 < len(a):
cur += 1
if day == a[cur] or day == a[cur] + 1:
cap = v
while cap > 0 and (day == a[cur] or day == a[cur] + 1):
take = min(cap, b[cur])
cap -= take
b[cur] -= take
ans += take
if b[cur] == 0:
if cur + 1 == len(a):
break
else:
cur += 1
day += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
d = [0] * 3001
for _ in range(n):
a, b = map(int, input().split())
d[a - 1] += b
sum = min(v, d[0])
d[0] = max(0, d[0] - v)
for i in range(1, 3001):
sum += min(v, d[i - 1] + d[i])
d[i] = max(0, d[i] - max(0, v - d[i - 1]))
print(sum)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = [int(c) for c in input().split()]
m = [[0, 0] for i in range(3003)]
for i in range(n):
a, b = [int(c) for c in input().split()]
m[a][1] += b
m[a + 1][0] += b
res = 0
for i in range(1, 3002):
if v <= m[i][0]:
res += v
else:
from_future = v - m[i][0]
got_fr = min(from_future, m[i][1])
res += m[i][0] + got_fr
m[i + 1][0] -= got_fr
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
import sys
def minp():
return sys.stdin.readline().strip()
A = [0] * 3005
n, v = map(int, minp().split())
for i in range(n):
a, b = map(int, minp().split())
A[a] += b
r = 0
for i in range(1, len(A) - 1):
z = min(v, A[i - 1])
A[i - 1] -= z
w = min(v - z, A[i])
A[i] -= w
r += z + w
print(r)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
def a():
n, v = list(map(int, input().split(" ")))
d = []
for i in range(n):
d.append(list(map(int, input().split(" "))))
d.sort()
cur = 0
nex = 0
k = 0
r = 0
for i in range(d[-1][0] + 2):
nex = 0
p = v
if k != n:
while d[k][0] < i:
k += 1
if k == n:
break
if k != n:
while d[k][0] == i:
nex += d[k][1]
k += 1
if k == n:
break
r += min(p, cur)
p -= min(p, cur)
r += min(p, nex)
cur = nex - min(p, nex)
return r
print(a())
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL 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 STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR IF VAR VAR WHILE VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
[n, v] = input().split()
v1 = []
for i in range(3002):
v1.append(0)
v = int(v)
maxx = 0
for i in range(int(n)):
[a, b] = input().split()
v1[int(a)] += int(b)
maxx = max(int(a), maxx)
res = 0
for i in range(1, maxx + 2):
delt = min(v, v1[i] + v1[i - 1])
res += delt
d = v1[i - 1] - delt
v1[i] += min(d, 0)
print(res)
|
ASSIGN LIST VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
N = 3005
n, v = map(int, input().split())
ripe = [0] * N
for i in range(n):
a, b = map(int, input().split())
ripe[a] += b
t = 0
ans = 0
for i in range(N):
if ripe[i] + t <= v:
ans += ripe[i] + t
t = 0
else:
ans += min(t, v)
ans += min(max(0, v - t), ripe[i])
t = max(0, ripe[i] - max(0, v - t))
print(ans)
|
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = [int(i) for i in input().split()]
d = {}
for i in range(n):
a, b = [int(i) for i in input().split()]
if a in d:
d[a] += b
else:
d[a] = b
set_tree = sorted(d)
set_tree = list(range(1, max(set_tree) + 2))
set_tree.append(0)
d[0] = 0
S = 0
for i in set_tree:
if i in d:
None
else:
d[i] = 0
for i in set_tree[:-1]:
if d[i] <= v:
S += d[i]
elif d[i] >= 2 * v:
S += v
d[i + 1] = d[i + 1] + v
else:
S += v
d[i + 1] += d[i] - v
print(S)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR NONE ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
li = []
for i in range(n):
tp = [int(x) for x in input().split()]
li.append(tp)
li.sort(key=lambda x: x[0])
d = {}
end = {}
distinct = set()
for i in range(n):
if d.get(li[i][0], -1) == -1:
d[li[i][0]] = i
if i < n - 1 and li[i][0] != li[i + 1][0]:
end[li[i][0]] = i
distinct.add(li[i][0])
to = set()
for ele in distinct:
if ele + 1 not in distinct:
to.add(ele + 1)
for ele in to:
distinct.add(ele)
distinct = list(distinct)
distinct.sort()
end[li[n - 1][0]] = n - 1
fruit = 0
i = 0
while i < len(distinct):
ele = distinct[i]
k = v
if d.get(ele - 1, -1) != -1:
start = d.get(ele - 1)
else:
start = d.get(ele)
ennd = end[ele] if end.get(ele, -1) != -1 else end[ele - 1]
for j in range(start, ennd + 1):
if k == 0:
break
elif li[j][1] > 0:
vl = min(li[j][1], k)
k -= vl
li[j][1] -= vl
fruit += vl
i += 1
print(fruit)
|
ASSIGN 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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
w = []
q = [v for i in range(3003)]
for i in range(n):
w.append(list(map(int, input().split())))
w = sorted(w, reverse=True)
s = 0
for i in w:
a = i[0]
b = i[1]
if q[a + 1] >= b:
q[a + 1] -= b
s += b
b = 0
else:
b -= q[a + 1]
s += q[a + 1]
q[a + 1] = 0
if q[a] >= b:
q[a] -= b
s += b
b = 0
else:
b -= q[a]
s += q[a]
q[a] = 0
print(s)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER 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 VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
d = {}
for i in range(n):
a, b = map(int, input().split())
if a in d:
d[a] += b
else:
d[a] = b
mi = min(d.keys())
ma = max(d.keys())
c = 0
for i in range(mi, ma + 3):
quota = v
if i - 1 in d:
if quota > d[i - 1]:
c += d[i - 1]
quota -= d[i - 1]
d[i - 1] = 0
else:
c += quota
d[i - 1] -= quota
quota = 0
if i in d:
if quota > d[i]:
c += d[i]
quota -= d[i]
d[i] = 0
else:
c += quota
d[i] -= quota
quota = 0
print(c)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
R = lambda: list(map(int, input().split()))
n, v = R()
M = 3005
x = [0] * M
for i in range(n):
a, b = R()
x[a - 1] += b
y = [0] * M
s = 0
for i in range(M):
a = min(v, y[i])
b = min(v - a, x[i])
s += a + b
if i < M - 1:
y[i + 1] = x[i] - b
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = map(int, input().split())
l = []
for i in range(n):
l += [list(map(int, input().split()))]
l.sort()
r = [0] * (3000 + 2)
t = 0
for i in range(n):
if r[l[i][0]] + l[i][1] <= v:
r[l[i][0]] += l[i][1]
elif r[l[i][0]] + r[l[i][0] + 1] + l[i][1] <= 2 * v:
t = r[l[i][0]]
r[l[i][0]] += v - r[l[i][0]]
l[i][1] -= v - t
r[l[i][0] + 1] += l[i][1]
else:
r[l[i][0]] = v
r[l[i][0] + 1] = v
print(sum(r))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
-----Input-----
The first line contains two space-separated integers n and v (1 β€ n, v β€ 3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 β€ a_{i}, b_{i} β€ 3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
-----Output-----
Print a single integer β the maximum number of fruit that Valera can collect.
-----Examples-----
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
-----Note-----
In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
|
n, v = [int(x) for x in input().split(" ")]
a_dict = {}
m = 0
p = 0
for tree in range(n):
a, b = [int(x) for x in input().split(" ")]
m = max(a, m)
if a in a_dict.keys():
a_dict[a] += b
else:
a_dict[a] = b
for day in range(m + 2):
if day not in a_dict.keys():
a_dict[day] = 0
for day in range(1, m + 2):
y = min(v, a_dict[day - 1])
a_dict[day - 1] -= y
z = min(v - y, a_dict[day])
a_dict[day] -= z
p += z + y
print(p)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT 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 STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
def main():
n = int(input())
s, t = str(input()), str(input())
p = [([0] * 26) for _ in range(26)]
dist = 0
for i in range(n):
if s[i] != t[i]:
j = ord(s[i]) - ord("a")
k = ord(t[i]) - ord("a")
p[j][k] = i + 1
dist += 1
for i in range(26):
for j in range(26):
if i != j and p[i][j] > 0 and p[j][i] > 0:
print(dist - 2)
print(p[i][j], p[j][i])
return
for i in range(26):
for j in range(26):
if i != j and p[i][j] > 0 and max(p[j]) > 0:
print(dist - 1)
for k in range(26):
if p[j][k] > 0:
print(p[i][j], p[j][k])
return
print(dist)
print(-1, -1)
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = input()
s1, s2 = input(), input()
l2, l3 = [], []
l1 = [
[l2.append((s1[x] + s2[x], x)), l3.append((s2[x] + s1[x], x))]
for x in range(len(s1))
if s1[x] != s2[x]
]
d1, d2 = dict(l2), dict(l3)
ins = set(d1.keys()) & set(d2.keys())
if ins:
e = ins.pop()
print(len(l1) - 2)
print(d1[e] + 1, d2[e] + 1)
return
s1, s2 = {y[0][0]: y[1] for y in l2}, {y[0][1]: y[1] for y in l2}
ins = set(s1.keys()) & set(s2.keys())
if ins:
e = ins.pop()
print(len(l1) - 1)
print(s1[e] + 1, s2[e] + 1)
return
print(len(l1))
print(-1, -1)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
import sys
n = int(input())
a = input()
b = input()
l = 0
c = [[(0) for j in range(26)] for i in range(26)]
for i in range(n):
if a[i] != b[i]:
l += 1
c[ord(a[i]) - ord("a")][ord(b[i]) - ord("a")] = i + 1
for i in range(26):
for j in range(26):
if i == j or c[i][j] == 0 or c[j][i] == 0:
continue
print(l - 2)
print(c[i][j], c[j][i])
sys.exit(0)
for i in range(26):
for j in range(26):
if i == j or c[i][j] == 0 or max(c[j]) == 0:
continue
print(l - 1)
print(c[i][j], end=" ")
for k in range(26):
if c[j][k] > 0:
print(c[j][k])
sys.exit(0)
print(l)
print(-1, -1)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
a = []
x = y = -2
h = 0
for i in range(26):
a.append([])
for j in range(26):
a[i].append(-1)
for i in range(n):
if s[i] != t[i]:
h += 1
a[ord(s[i]) - ord("a")][ord(t[i]) - ord("a")] = i
if a[ord(t[i]) - ord("a")][ord(s[i]) - ord("a")] != -1:
x = i
y = a[ord(t[i]) - ord("a")][ord(s[i]) - ord("a")]
if x == -2:
for i in range(26):
for j in range(26):
if a[i][j] != -1:
for k in range(26):
if a[j][k] != -1:
x = a[i][j]
y = a[j][k]
if x != -2:
if s[x] == t[y]:
h -= 1
if s[y] == t[x]:
h -= 1
print(h)
print(x + 1, y + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
def main():
n = int(input())
s = input()
t = input()
p = {}
hd = sum(int(x != y) for x, y in zip(s, t))
for i, (x, y) in enumerate(zip(s, t)):
if x != y:
if x in p and y in p[x]:
print(hd - 2)
print(i + 1, p[x][y] + 1)
return
else:
if y not in p:
p[y] = {}
p[y][x] = i
for x in p:
c = p.keys() & p[x].keys()
if c:
print(hd - 1)
c = c.pop()
print(p[x][c] + 1, p[c].popitem()[1] + 1)
return
print(hd)
print(-1, -1)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER RETURN IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
__author__ = "ruckus"
n = int(input())
s = input()
t = input()
dif = {}
hem = 0
for i in range(n):
if s[i] != t[i]:
dif[i] = [s[i], t[i]]
hem += 1
change = []
probed = []
k = 0
for i in dif.keys():
if dif[i] in probed:
continue
probed.append(dif[i])
k += 1
for j in list(dif.keys())[k:]:
if dif[i] == dif[j][::-1]:
print(hem - 2)
print(i + 1, j + 1)
quit()
if not change and (dif[i][0] == dif[j][1] or dif[j][0] == dif[i][1]):
change = [i, j]
if change:
print(hem - 1)
print(change[0] + 1, change[1] + 1)
else:
print(hem)
print("-1 -1")
|
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
import time
class Profiler(object):
def __enter__(self):
self._startTime = time.time()
def __exit__(self, type, value, traceback):
print("Elapsed time: {:.3f} sec".format(time.time() - self._startTime))
n = int(input())
a = input()
b = input()
indexes = list()
d = {}
f1 = False
f2 = False
df = 0
i1 = 0
i2 = 0
for i in range(n):
if a[i] != b[i]:
df += 1
indexes.append(i)
d[b[i]] = i
for i in indexes:
if a[i] in d:
f1 = True
j = d[a[i]]
i1 = i + 1
i2 = j + 1
if a[j] == b[i]:
f2 = True
break
if f2:
print(str(df - 2))
print(i1.__str__() + " " + i2.__str__())
elif f1:
print(str(df - 1))
print(i1.__str__() + " " + i2.__str__())
else:
print(str(df))
print("-1 -1")
|
IMPORT CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
xxx = 0
a1 = []
a2 = []
a = int(input())
x = input()
y = input()
of1 = []
of2 = []
a1 = {}
a2 = {}
for i in "abcdefghijklmnopqrstuvwxyz":
a1[i] = []
a2[i] = []
for i in range(a):
if x[i] != y[i]:
a1[x[i]].append(i + 1)
a2[y[i]].append(i + 1)
else:
xxx += 1
for i in "abcdefghijklmnopqrstuvwxyz":
for j in "abcdefghijklmnopqrstuvwxyz":
if j != i:
aa1 = a1[i]
bb1 = a2[j]
cc1 = a1[j]
dd1 = a2[i]
ee = set(aa1).intersection(bb1)
ff = set(cc1).intersection(dd1)
if ee != set() and ff != set():
print(a - xxx - 2)
print(list(ee)[0], list(ff)[0])
quit()
for i in "abcdefghijklmnopqrstuvwxyz":
for j in "abcdefghijklmnopqrstuvwxyz":
if j != i:
aa1 = a1[i]
bb1 = a2[j]
cc1 = a1[j]
dd1 = a2[i]
ee = set(aa1).intersection(bb1)
ff = set(cc1).intersection(dd1)
if ee != set():
if cc1 == [] and dd1 == []:
print(a - xxx)
print(-1, -1)
quit()
print(a - xxx - 1)
if len(cc1) > 0:
print(list(ee)[0], cc1[0])
else:
print(list(ee)[0], dd1[0])
quit()
elif ff != set():
if aa1 == [] and bb1 == []:
print(a - xxx)
print(-1, -1)
quit()
print(a - xxx - 1)
if len(aa1) > 0:
print(list(ff)[0], aa1[0])
else:
print(list(ff)[0], bb1[0])
quit()
print(a - xxx)
print(-1, -1)
|
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR STRING ASSIGN VAR VAR LIST ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR STRING FOR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR STRING FOR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR IF VAR LIST VAR LIST EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR IF VAR LIST VAR LIST EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
num = int(input())
a = input()
b = input()
dic = {}
lis = []
ham = 0
swap1 = -1
swap2 = -1
p = False
q = False
for i in range(num):
if a[i] != b[i]:
ham += 1
lis.append(i)
dic[b[i]] = i
for i in lis:
if a[i] in dic:
p = True
swap1 = i + 1
f = dic[a[i]]
swap2 = f + 1
if a[f] == b[i]:
q = True
break
print(ham - (2 if q else 1 if p else 0))
print(swap1, swap2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
pair2ind = {}
letters_s = [0] * 26
letters_t = [0] * 26
non_common = set()
cnt = 0
for i in range(n):
if s[i] != t[i]:
pair2ind[s[i], t[i]] = i + 1
letters_s[ord(s[i]) - ord("a")] = i + 1
letters_t[ord(t[i]) - ord("a")] = i + 1
non_common.add(i + 1)
cnt += 1
sim = -1
for i in range(26):
if letters_s[i] != 0 and letters_t[i] != 0:
sim = letters_s[i]
break
else:
print(cnt)
print(-1, -1)
exit()
for i in range(n):
if s[i] != t[i]:
if (t[i], s[i]) in pair2ind:
print(cnt - 2)
print(pair2ind[s[i], t[i]], pair2ind[t[i], s[i]])
exit()
non_common.remove(sim)
print(cnt - 1)
print(sim, letters_t[ord(s[sim - 1]) - ord("a")])
exit()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
def solve():
r = 0
d = {}
for i in range(n):
if a[i] != b[i]:
r += 1
d[a[i], b[i]] = i + 1
symbols = [chr(ord("a") + i) for i in range(26)]
for i in symbols:
for j in symbols:
if (i, j) in d and (j, i) in d:
return r - 2, d[i, j], d[j, i]
for i in symbols:
for j in symbols:
for k in symbols:
if (i, j) in d and (j, k) in d:
return r - 1, d[i, j], d[j, k]
return r, -1, -1
n = int(input())
a = input()
b = input()
ans = solve()
print(ans[0], "\n", ans[1], " ", ans[2], sep="")
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR FOR VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
def id(c):
return ord(c) - ord("a")
diff = 0
for i in range(n):
if s[i] != t[i]:
diff += 1
has = [[(0) for i in range(30)] for j in range(30)]
x = [(0) for i in range(30)]
y = [(0) for i in range(30)]
if diff == 0:
print("0\n-1 -1")
elif diff == 1:
print("1\n-1 -1")
else:
for i in range(n):
if s[i] != t[i] and has[id(s[i])][id(t[i])]:
print("{} \n{} {}".format(diff - 2, has[id(s[i])][id(t[i])], i + 1))
quit()
has[id(t[i])][id(s[i])] = i + 1
for i in range(n):
if x[id(s[i])] != 0 and s[i] != t[i]:
print("{} \n{} {}".format(diff - 1, x[id(s[i])], i + 1))
quit()
if y[id(t[i])] != 0 and s[i] != t[i]:
print("{} \n{} {}".format(diff - 1, y[id(t[i])], i + 1))
quit()
if s[i] != t[i]:
x[id(t[i])] = y[id(s[i])] = i + 1
print("{} \n{} {}".format(diff, -1, -1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
def solve(n, S, T):
st = dict()
ts = dict()
s = dict()
t = dict()
dist = 0
for i, (si, ti) in enumerate(zip(S, T), 1):
if si != ti:
st[si, ti] = i
ts[ti, si] = i
s[si] = i
t[ti] = i
dist += 1
for key, i in st.items():
if key in ts:
j = ts[key]
return dist - 2, min(i, j), max(i, j)
for si, i in s.items():
if si in t:
j = t[si]
return dist - 1, min(i, j), max(i, j)
return dist, -1, -1
n = int(input())
S = input()
T = input()
dist, i, j = solve(n, S, T)
print(dist)
print(i, j)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
_, s, t = input(), input(), input()
d = 0
p = [[(-1) for _ in range(26)] for _ in range(26)]
a, b = [(-1) for _ in range(26)], [(-1) for _ in range(26)]
for i in range(len(s)):
if s[i] != t[i]:
cs = ord(s[i]) - 97
ct = ord(t[i]) - 97
d += 1
p[cs][ct] = i + 1
a[cs] = i + 1
b[ct] = i + 1
for i in range(26 * 26):
if p[i // 26][i % 26] > -1 and p[i % 26][i // 26] > -1:
print(d - 2)
print(p[i // 26][i % 26], p[i % 26][i // 26])
break
else:
for i in range(26):
if a[i] > -1 and b[i] > -1:
print(d - 1)
print(a[i], b[i])
break
else:
print(d)
print(-1, -1)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n, s, t = int(input()), input(), input()
d = {}
wrongs = []
ansD, ansI, ansJ = 0, -1, -1
for i in range(n):
if s[i] != t[i]:
ansD += 1
wrongs.append(i)
d[t[i]] = i
perfectSwapped = False
swapped = False
for i in wrongs:
if s[i] in d:
swapped = True
ansI = i + 1
j = d[s[i]]
ansJ = j + 1
if s[j] == t[i]:
perfectSwapped = True
break
print(ansD - (2 if perfectSwapped else 1 if swapped else 0))
print(ansI, ansJ)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
a = input()
b = input()
cnt = 0
index1 = -1
index2 = -1
mp = {}
flag1 = True
flag2 = True
l = [chr(ord("a") + i) for i in range(26)]
for i in range(n):
if a[i] != b[i]:
cnt += 1
mp[a[i], b[i]] = i
for i in l:
if flag1:
for j in l:
if flag1:
if (i, j) in mp:
if (j, i) in mp:
index1 = mp[i, j] + 1
index2 = mp[j, i] + 1
flag1 = False
else:
for k in l:
if (j, k) in mp:
index1 = mp[i, j] + 1
index2 = mp[j, k] + 1
flag2 = False
elif (k, i) in mp:
index1 = mp[i, j] + 1
index2 = mp[k, i] + 1
flag2 = False
print(cnt - (2 if flag1 == False else 1 if flag2 == False else 0))
print(index1, index2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR FOR VAR VAR IF VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n, s, t, a, error, ans, kappa = int(input()), str(input()), str(input()), {}, 0, -1, 0
for i in range(n):
if s[i] != t[i]:
a[s[i] + t[i]] = i
error += 1
for c1 in "abcdefghijklmnopqrstuvwxyz":
for c2 in "abcdefghijklmnopqrstuvwxyz":
if c1 == c2 or kappa == 2:
continue
if c1 + c2 in a and c2 + c1 in a and kappa < 2:
ans = a[c1 + c2], a[c2 + c1]
kappa = 2
if kappa == 0:
for c3 in "abcdefghijklmnopqrstuvwxyz":
if c1 != c3 and c1 + c2 in a and c2 + c3 in a:
ans = a[c1 + c2], a[c2 + c3]
kappa = 1
print(error - kappa)
print("%d %d" % ((ans[0] + 1, ans[1] + 1) if ans != -1 else (-1, -1)))
|
ASSIGN VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR DICT NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER FOR VAR STRING FOR VAR STRING IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR STRING IF VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = input()
s1, s2 = input(), input()
l1 = [[x, [s1[x], s2[x]]] for x in range(len(s1)) if s1[x] != s2[x]]
d1, d2 = dict([(y[1][0] + y[1][1], y[0]) for y in l1]), dict(
[(y[1][1] + y[1][0], y[0]) for y in l1]
)
ins = set(d1.keys()) & set(d2.keys())
if ins:
e = ins.pop()
print(len(l1) - 2)
print(d1[e] + 1, d2[e] + 1)
exit(0)
s1, s2 = dict([(y[1][0], y[0]) for y in l1]), dict([(y[1][1], y[0]) for y in l1])
ins = set(s1.keys()) & set(s2.keys())
if ins:
e = ins.pop()
print(len(l1) - 1)
print(s1[e] + 1, s2[e] + 1)
exit(0)
print(len(l1))
print(-1, -1)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
diff = {}
dis = 0
for i in range(len(s)):
if s[i] != t[i]:
dis += 1
diff[s[i] + t[i]] = i + 1
for d in diff.keys():
if diff.get(d[::-1], 0) > 0:
print(dis - 2)
print(diff[d], diff[d[::-1]])
exit()
for d in diff.keys():
for dd in diff.keys():
if d[0] == dd[1] or d[1] == dd[0]:
print(dis - 1)
print(diff[d], diff[dd])
exit()
print(dis)
print(-1, -1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
dis = 0
d = [[(False) for i in range(30)] for i in range(30)]
x = [[(0) for i in range(30)] for i in range(30)]
for i in range(n):
if s[i] != t[i]:
dis += 1
d[ord(s[i]) - ord("a")][ord(t[i]) - ord("a")] = True
x[ord(s[i]) - ord("a")][ord(t[i]) - ord("a")] = i + 1
def progress():
for i in range(26):
for j in range(26):
if d[i][j] and d[j][i]:
print("{}\n{} {}".format(dis - 2, x[i][j], x[j][i]))
return 0
for i in range(26):
for j in range(26):
if d[i][j]:
for t in range(26):
if d[j][t]:
print("{}\n{} {}".format(dis - 1, x[i][j], x[j][t]))
return 0
print("{}\n{} {}".format(dis, -1, -1))
progress()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER EXPR FUNC_CALL VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s, t = input(), input()
alpha = list("abcdefghijklmnopqrstuvwxyz")
spair, tpair = dict(), dict()
x = [1] * n
k = n
d = 0
u, v = -1, -1
dd = dict()
for i in range(n):
if s[i] == t[i]:
k = k - 1
else:
dd[s[i] + t[i]] = str(i + 1)
for i in alpha:
for j in alpha:
if i + j in dd and j + i in dd:
print(k - 2)
print(dd[i + j] + " " + dd[j + i])
raise SystemExit
for i in alpha:
for j in alpha:
for l in alpha:
if i + j in dd and j + l in dd:
print(k - 1)
print(dd[i + j] + " " + dd[j + l])
raise SystemExit
print(k)
print("-1 -1")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR FOR VAR VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
k, l = 0, 0
state = 0
hd = 0
m = {}
for i in range(n):
if s[i] != t[i]:
hd += 1
cs = s[i]
ct = t[i]
cst = cs + ct
if cst not in m:
m[cst] = i + 1
for pair in m:
r = pair[1] + pair[0]
if r in m:
print(hd - 2)
print(m[pair], m[r])
exit()
for pair in m:
for p in m:
if pair == p:
continue
if p[0] == pair[1] or p[1] == pair[0]:
print(hd - 1)
print(m[pair], m[p])
exit()
print(hd)
print(-1, -1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
p = 0
dist = 0
m = [[] for i in range(0, 26)]
sr = []
while p < len(s):
if s[p] != t[p]:
m[ord(s[p]) - ord("a")].append((t[p], p))
dist += 1
p += 1
p = 0
while p < len(s):
if s[p] != t[p]:
flag = False
for i in sr:
if i[0] == s[p] and i[1] == t[p]:
flag = True
break
if flag == True:
p += 1
continue
sr.append((s[p], t[p]))
for i in m[ord(t[p]) - ord("a")]:
if i[0] == s[p]:
dist -= 2
print(dist)
print(p + 1, i[1] + 1)
quit()
p += 1
p = 0
while p < len(s):
if s[p] != t[p]:
if len(m[ord(t[p]) - ord("a")]) > 0:
dist -= 1
print(dist)
print(p + 1, m[ord(t[p]) - ord("a")][0][1] + 1)
quit()
p += 1
print(dist)
print(-1, -1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
def gao():
n = int(input())
a = input()
b = input()
mp = {}
cnt = 0
for i in range(n):
if a[i] != b[i]:
cnt += 1
mp[a[i], b[i]] = i + 1
l = [chr(ord("a") + i) for i in range(26)]
for i in l:
for j in l:
if (i, j) in mp and (j, i) in mp:
print(cnt - 2)
print(mp[i, j], mp[j, i])
return
for i in l:
for j in l:
for k in l:
if (i, j) in mp and (j, k) in mp:
print(cnt - 1)
print(mp[i, j], mp[j, k])
return
print(cnt)
print(-1, -1)
gao()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN FOR VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = list(input())
t = list(input())
d = {}
ans = 0
x, y = -1, -1
for i in range(n):
if s[i] != t[i]:
d[s[i], t[i]] = i
ans += 1
l = [chr(i + 97) for i in range(26)]
for i in l:
for j in l:
if (i, j) in d and (j, i) in d:
ans -= 2
x = d[i, j] + 1
y = d[j, i] + 1
break
if x != -1:
break
if x == y == -1:
for i in l:
for j in l:
for k in l:
if (i, j) in d and (j, k) in d:
ans -= 1
x = d[i, j] + 1
y = d[j, k] + 1
break
if x != -1:
break
print(ans)
print(x, y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER FOR VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
diff = []
wrong_t = {}
def distance(n, s, t):
count = 0
for i in range(n):
if s[i] != t[i]:
diff.append(i)
wrong_t[t[i]] = i
count += 1
return count
def minDistance():
m_ben = 0
m_i = -2
m_j = -2
for i in diff:
v = wrong_t[s[i]] if s[i] in wrong_t else None
if v != None:
m_ben = 1
m_i = i
m_j = v
if s[v] == t[i]:
return 2, i, v
return m_ben, m_i, m_j
n = int(input())
s = input()
t = input()
d = distance(n, s, t)
m_ben, m_i, m_j = minDistance()
print(d - m_ben)
print("{0} {1}".format(m_i + 1, m_j + 1))
|
ASSIGN VAR LIST ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NONE IF VAR NONE ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
alth = "abcdefghijklmnopqrstuvwxyz"
n = int(input())
S = input()
T = input()
heming = 0
first = [-1] * 26
second = [-1] * 26
first_second = [-1] * 676
for i in range(n):
if S[i] != T[i]:
heming += 1
temp = alth.find(S[i])
temp2 = alth.find(T[i])
first[temp] = i
second[temp2] = i
first_second[temp * 26 + temp2] = i
error_1 = 0
error_2 = 0
for i in range(676):
temp = i % 26
temp2 = i // 26
if first_second[i] != -1 and first_second[temp * 26 + temp2] != -1:
error_1 = 1
print(heming - 2)
print(first_second[i] + 1, first_second[temp * 26 + temp2] + 1)
break
if error_1 == 0:
for i in range(26):
if first[i] != -1 and second[i] != -1:
error_2 = 2
print(heming - 1)
print(first[i] + 1, second[i] + 1)
break
if error_2 == 0:
print(heming)
print(-1, -1)
|
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
import sys
n = int(input())
s = input()
t = input()
def ff(ch):
return ord(ch) - ord("a")
def answer(a, b, sc):
print(res + sc)
print(a + 1, b + 1)
return
matrix = [([None] * 26) for _ in range(26)]
res = 0
for i in range(len(s)):
matrix[ff(s[i])][ff(t[i])] = i
if s[i] != t[i]:
res += 1
for i in range(26):
for j in range(i):
if matrix[i][j] is not None and matrix[j][i] is not None:
answer(matrix[i][j], matrix[j][i], -2)
for i in range(26):
for h in range(26):
if h == i:
continue
for v in range(26):
if v == i:
continue
if matrix[h][i] is not None and matrix[i][v] is not None:
answer(matrix[h][i], matrix[i][v], -1)
answer(-2, -2, 0)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN ASSIGN VAR BIN_OP LIST NONE NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NONE VAR VAR VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR VAR VAR NONE VAR VAR VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
import sys
n = int(input())
s = input()
t = input()
arr = {}
f = 0
for idx in range(n):
if s[idx] != t[idx]:
f += 1
arr[s[idx] + t[idx]] = idx
for k in arr.keys():
if k[1] + k[0] in arr:
print(f - 2)
print(str(arr[k] + 1) + " " + str(arr[k[1] + k[0]] + 1))
sys.exit(0)
for k in arr.keys():
for l in arr.keys():
if k[0] == l[1] or k[1] == l[0]:
print(f - 1)
print(str(arr[k] + 1) + " " + str(arr[l] + 1))
sys.exit(0)
print(f)
print("-1 -1")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
n = int(input())
s = input()
t = input()
p = [-1, -1]
a = [([-1] * 26) for i in range(26)]
k = 0
for i in range(n):
if t[i] != s[i]:
k += 1
for i in range(n):
if t[i] != s[i]:
if a[ord(t[i]) - 97][ord(s[i]) - 97] != -1:
print(k - 2)
print(a[ord(t[i]) - 97][ord(s[i]) - 97] + 1, i + 1)
exit()
a[ord(s[i]) - 97][ord(t[i]) - 97] = i
for i in range(n):
if t[i] != s[i]:
for j in range(26):
if a[j][ord(s[i]) - 97] != -1:
print(k - 1)
print(a[j][ord(s[i]) - 97] + 1, i + 1)
exit()
a[ord(s[i]) - 97][ord(t[i]) - 97] = i
print(k)
print(-1, -1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
-----Input-----
The first line contains integer n (1 β€ n β€ 200 000) β the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
-----Output-----
In the first line, print number x β the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 β€ i, j β€ n, i β j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
-----Examples-----
Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1
-----Note-----
In the second test it is acceptable to print i = 2, j = 3.
|
YNaXbdBeHKpwfIm = int
YNaXbdBeHKpwfIi = input
YNaXbdBeHKpwfIj = range
YNaXbdBeHKpwfIR = len
YNaXbdBeHKpwfID = print
YNaXbdBeHKpwfIl = exit
YNaXbdBeHKpwfIt = YNaXbdBeHKpwfIm
YNaXbdBeHKpwfIx = YNaXbdBeHKpwfIi
YNaXbdBeHKpwfIz = YNaXbdBeHKpwfIj
YNaXbdBeHKpwfIW = YNaXbdBeHKpwfIR
YNaXbdBeHKpwfIO = YNaXbdBeHKpwfID
YNaXbdBeHKpwfIo = YNaXbdBeHKpwfIl
YNaXbdBeHKpwfIM = YNaXbdBeHKpwfIt
YNaXbdBeHKpwfIn = YNaXbdBeHKpwfIx
YNaXbdBeHKpwfIL = YNaXbdBeHKpwfIz
YNaXbdBeHKpwfIA = YNaXbdBeHKpwfIW
YNaXbdBeHKpwfIq = YNaXbdBeHKpwfIO
YNaXbdBeHKpwfIc = YNaXbdBeHKpwfIo
n = YNaXbdBeHKpwfIM(YNaXbdBeHKpwfIn())
s = YNaXbdBeHKpwfIn()
t = YNaXbdBeHKpwfIn()
YNaXbdBeHKpwfIs = {}
YNaXbdBeHKpwfIT = 0
for i in YNaXbdBeHKpwfIL(YNaXbdBeHKpwfIA(s)):
if s[i] != t[i]:
YNaXbdBeHKpwfIT += 1
YNaXbdBeHKpwfIs[s[i] + t[i]] = i + 1
for d in YNaXbdBeHKpwfIs.keys():
if YNaXbdBeHKpwfIs.get(d[::-1], 0) > 0:
YNaXbdBeHKpwfIq(YNaXbdBeHKpwfIT - 2)
YNaXbdBeHKpwfIq(YNaXbdBeHKpwfIs[d], YNaXbdBeHKpwfIs[d[::-1]])
YNaXbdBeHKpwfIc()
for d in YNaXbdBeHKpwfIs.keys():
for dd in YNaXbdBeHKpwfIs.keys():
if d[0] == dd[1] or d[1] == dd[0]:
YNaXbdBeHKpwfIq(YNaXbdBeHKpwfIT - 1)
YNaXbdBeHKpwfIq(YNaXbdBeHKpwfIs[d], YNaXbdBeHKpwfIs[dd])
YNaXbdBeHKpwfIc()
YNaXbdBeHKpwfIq(YNaXbdBeHKpwfIT)
YNaXbdBeHKpwfIq(-1, -1)
|
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(n):
s += a[i] * b[i]
m = max([abs(i) for i in b])
print(s + k * m)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
mul = [(a[x] * b[x]) for x in range(n)]
absb = [abs(x) for x in b]
mx = max(absb)
index = absb.index(mx)
su = sum(mul)
(
print(su + (a[index] - k) * b[index] - a[index] * b[index])
if b[index] < 0
else print(su + (a[index] + k) * b[index] - a[index] * b[index])
)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
interaction = 0
mx = -float("INF")
for item in b:
mx = max(mx, abs(item))
for i in range(n):
interaction += a[i] * b[i]
interaction += mx * k
print(interaction)
|
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 FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for _ in range(int(input().strip())):
n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
ans = 0
ans += sum(x * y for x, y in zip(a, b))
ans += k * max(map(abs, b))
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
from sys import flags
for _ in range(int(input())):
n, k = [int(a) for a in input().split()]
arr = [int(a) for a in input().split()]
brr = [int(a) for a in input().split()]
val = -float("inf")
for l in brr:
val = max(val, abs(l))
val2 = 0
for l in range(n):
val2 = val2 + arr[l] * brr[l]
print(val2 + val * k)
|
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 FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
def main():
t = int(input())
while t:
t -= 1
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ssum = sum([(n1 * n2) for n1, n2 in zip(a, b)])
mmax = max(b)
mmin = min(b)
if abs(mmin) > mmax:
ssum += k * abs(mmin)
else:
ssum += k * mmax
print(ssum)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for __ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mx, mn = max(b), min(b)
val = mx if abs(mx) > abs(mn) else mn
idx = b.index(val)
if val > 0:
a[idx] += k
else:
a[idx] -= k
s = 0
for i in range(n):
s = s + a[i] * b[i]
print(s)
|
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 VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for cas in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
a[i] = a[i] * b[i]
b[i] = abs(b[i])
s = sum(a)
p = max(b)
print(s + k * abs(p))
|
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
c = list(map(lambda x, y: x * y, a, b))
m = max(list(map(lambda x: abs(x), b)))
csum = sum(c)
print(csum + k * m)
|
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
T = int(input())
while T:
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = 0
for i in range(len(A)):
ans += A[i] * B[i]
B[i] = abs(B[i])
ans += K * max(B)
print(ans)
T -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
t = int(input())
for test in range(t):
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = sum(x * y for x, y in zip(a, b))
mx = 0
pair = 0
for i in range(n):
if abs(b[i]) > abs(mx):
mx = b[i]
pair = a[i]
elif abs(b[i]) == abs(mx) and abs(a[i]) > abs(pair):
pair = a[i]
s -= mx * pair
if mx < 0:
mx, pair = -mx, -pair
if (mx > 0) != (pair > 0):
if -k >= pair:
k += pair
pair = 0
else:
pair += k
k = 0
pair += k
s += mx * pair
print(s)
|
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 VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
tests = int(input())
for i in range(tests):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maximum = -(10**6)
ans = 0
for j in range(n):
ans += a[j] * b[j]
maximum = max(maximum, abs(b[j]))
ans += maximum * k
print(ans)
|
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 BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
T = int(input())
for j in range(T):
in1 = [int(i) for i in input().split()]
N, K = in1[0], in1[1]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
P = K * max([abs(l) for l in [max(B), min(B)]])
for i in range(0, N):
P += A[i] * B[i]
print(P)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER 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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
t = int(input())
for _ in range(0, t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum = 0
for i in range(0, n):
sum += a[i] * b[i]
max = 0
ii = 0
for i in range(0, n):
if max < abs(b[i]):
max = abs(b[i])
ii = i
if b[ii] < 0:
sum += -k * b[ii]
else:
sum += k * b[ii]
print(sum)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for t in range(int(input())):
temp = list(map(int, input().split()))
n = temp[0]
k = temp[1]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
x = abs(b[0])
for i in range(n):
ans += a[i] * b[i]
if abs(b[i]) > x:
x = abs(b[i])
ans += x * k
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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 FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
def temp(n, k):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
max_i = 0
m1 = abs(b[0])
j = 0
for i in range(n):
if m1 < abs(b[i]):
m1 = abs(b[i])
j = i
max_i += a[i] * b[i]
max_i = max_i + k * abs(b[j])
return max_i
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
print(temp(n, k))
|
FUNC_DEF 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for _ in range(int(input())):
n, k = map(int, input().split(" "))
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
c = 0
final = 0
for i in range(n):
c += a[i] * b[i]
final += a[i] * b[i]
for i in range(n):
p = 1 if b[i] >= 0 else -1
temp = c + p * k * b[i]
if temp > final:
final = temp
print(final)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for i in range(int(input())):
s = input().split()
s = [int(j) for j in s]
l1 = input().split()
l2 = input().split()
l1 = [int(j) for j in l1]
l2 = [int(j) for j in l2]
mx = abs(l2[0])
k = 0
for j in range(len(l2)):
if abs(l2[j]) > mx:
mx = abs(l2[j])
k = j
if l2[k] > 0:
l1[k] = l1[k] + s[1]
else:
l1[k] = l1[k] - s[1]
sum = 0
for j in range(s[0]):
sum = sum + l1[j] * l2[j]
print(sum)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for _ in range(int(input())):
arr = input().split()
n, k = int(arr[0]), int(arr[1])
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(n):
if b[i] < 0:
b[i] *= -1
a[i] *= -1
m = b.index(max(b))
a[m] += k
print(sum([(a[i] * b[i]) for i in range(n)]))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
for _ in range(int(input())):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
min_el = min(B)
max_el = max(B)
ind = 0
if abs(min_el) < max_el:
ind = B.index(max_el)
A[ind] = A[ind] + K
elif min_el == max_el:
if min_el >= 0:
ind = A.index(max(A))
A[ind] = A[ind] + K
else:
ind = A.index(min(A))
A[ind] = A[ind] - K
else:
ind = B.index(min_el)
A[ind] = A[ind] - K
res = 0
for a, b in zip(A, B):
res += a * b
print(res)
|
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N.
You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind.
In a single operation, you can increase or decrease any of the elements of array A by 1.
Find out the maximum value of interaction of the arrays that you can get.
------ Input ------
The first line of input contains a single integer T denoting number of test cases.
For each test case:
First line contains two space separated integers N, K.
Second line contains N space separated integers denoting array A.
Third line contains N space separated integers denoting array B.
------ Output ------
For each test case, output a single integer denoting the answer of the problem.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10^{5}$
$0 β€ |A[i]|, |B[i]| β€ 10^{5}$
$0 β€ K β€ 10^{9}$
------ Subtasks ------
Subtask #1 : (25 points)
$1 β€ N β€ 10$
$0 β€ |A[i]|, |B[i]| β€ 10$
$0 β€ K β€ 10$
Subtask #2 : (35 points)
$1 β€ N β€ 1000$
$0 β€ |A[i]|, |B[i]| β€ 1000$
$0 β€ K β€ 10^{5}$
Subtask #3 : (40 points)
$No additional constraints$
----- Sample Input 1 ------
2
2 2
1 2
-2 3
3 5
1 2 -3
-2 3 -5
----- Sample Output 1 ------
10
44
----- explanation 1 ------
In the first example,
you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
ans = 0
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
ans += a[i] * b[i]
d = ans
for i in range(n):
d = max(d, ans + k * b[i])
d = max(d, ans + -1 * k * b[i])
print(d)
|
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 NUMBER 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 FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.