description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
def potions(n): lst = [int(i) for i in input().split()] l = [] for potion in lst: l.append(potion) if potion < 0 and sum(l) < 0: l = sorted(l) l.pop(0) print(len(l)) n = int(input()) potions(n)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) ls = list(map(int, input().split())) drk, ans, hp = [], 0, 0 for i in ls: if i >= 0: ans, hp = ans + 1, hp + i elif hp + sum(drk) + i >= 0: drk.append(i) else: try: temp = min(drk) except ValueError: continue if temp < i: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) li = list(map(int, input().split())) q = [] c = 0 v = 0 for i in range(0, n): v += li[i] c += 1 if li[i] < 0: q.append(li[i]) q.sort() if v < 0: v -= q[0] q.sort() q.pop(0) q.sort() c = c - 1 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CAL...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
def solve(n, a): count = health = 0 i = 0 while i < len(a): health += a[i] count += 1 if health < 0: min_dam = min(a[: i + 1]) a.remove(min_dam) health -= min_dam count -= 1 continue i += 1 return count n = int...
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUN...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) a = [int(x) for x in input().split()] s = 0 k = 0 b = [] for i in range(0, n): s = s + a[i] k = k + 1 if a[i] < 0: b.append(a[i]) while s < 0: p = min(b) s = s - p k = k - 1 b.remove(p) print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CA...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) a = list(map(lambda x: int(x), input().split())) s = 0 ans = [] for i in range(n): if s + a[i] >= 0: s += a[i] ans.append(a[i]) ans.sort() elif ans and ans[0] < a[i]: s += a[i] - ans[0] ans.pop(0) ans.append(a[i]) ans.sort() print(len(ans)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMB...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
def func(): n = int(input()) l = list(map(int, input().split())) pois = 0 health = 0 neg_pos = [] for potion in l: if potion >= 0: pois += 1 health += potion elif potion + health >= 0: pois += 1 health += potion neg_pos....
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VA...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) arr = list(map(int, input().split())) dp = [] for i in arr: dp.append(i) if i >= 0: continue dp.sort() if sum(dp) < 0: dp.pop(0) print(len(dp))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
a = int(input()) arr = [int(arr) for arr in input().split()] total = 0 count = 0 neg = [] for i in arr: total = total + i count = count + 1 if i < 0: neg.append(i) if total < 0: total = total - min(neg) neg.remove(min(neg)) count = count - 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
def solve(l): c, s = 0, 0 k = [] for i in range(len(l)): if l[i] >= 0: s = s + l[i] c = c + 1 else: k.append(l[i]) s = s + l[i] c = c + 1 while s < 0: k.sort() s = s - k[0] ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR N...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
def put_into_list(num: int, arr: list): if not arr: arr.append(num) return for i in range(len(arr)): if arr[i] > num: arr.insert(i, num) return arr.append(num) def poisons_simple(n: int, dr: list): health = 0 amount_pois = 0 neg_pois = [] for...
FUNC_DEF VAR VAR IF VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR ...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) lis = list(map(int, input().split())) ans = 0 arr = list() for i in lis: ans += i arr.append(i) arr.sort() while ans < 0: ans -= arr[0] arr.pop(0) print(len(arr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) s = count = 0 taken = [] ncount = 0 for i in list(map(int, input().split())): if i >= 0: count += 1 ncount += 1 s += i elif s + i >= 0: s += i count += 1 taken.append(i) elif len(taken) > 0: v = min(taken) if s + i - v >= 0 and...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL V...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
def poisons(n: int, dr: list): health = 0 amount_pois = 0 neg_pois = [] for i in range(n): if dr[i] >= 0: amount_pois += 1 health += dr[i] continue if health + dr[i] >= 0: amount_pois += 1 health += dr[i] neg_pois.ap...
FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_C...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
input() x = map(int, input().split()) m = 0 m1 = [] c = 0 for i in x: if m + i >= 0: if i < 0: m1 += [i] elif m1: if i > min(m1): m = m - min(m1) m1.remove(min(m1)) m1.append(i) c -= 1 if m + i >= 0: m += i c += 1 pr...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR LIST VAR IF VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
import sys input = sys.stdin.readline n, x = map(int, input().split()) a = [int(x) for x in input().split()] dp = [[0, 0, 0, 0] for i in range(n)] for i in range(n): dp[i][0] = max(a[i], dp[i - 1][0] + a[i]) dp[i][1] = max(a[i] * x, dp[i - 1][0] + a[i] * x) dp[i][2] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSI...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def printarr(dp): for i in dp: print(*i) n, m = map(int, input().split()) a = [0] + list(map(int, input().split())) dp = [[0, 0, 0] for i in range(n + 1)] ma = -1 for i in range(1, n + 1): dp[i][0] = max(dp[i - 1][0] + a[i], 0) dp[i][1] = max(dp[i - 1][1] + a[i] * m, dp[i - 1][0] + a[i] * m) d...
FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NU...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) arr = [int(x) for x in input().split()] dp = [[(0) for _ in range(n)] for _ in range(3)] dp[0][0] = max(arr[0], 0) dp[1][0] = max(arr[0] * x, 0) dp[2][0] = max(arr[0], 0) answer = max(dp[0][0], dp[1][0], dp[2][0]) for i in range(1, n): dp[0][i] = max(dp[0][i - 1] + arr[i], arr[i], 0...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBE...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, m = map(int, input().split()) lis = list(map(int, input().split())) pref = suff = main = ans = 0 for i in lis: pref = max(pref + i, 0) suff = max(suff + i * m, pref) main = max(main + i, suff) ans = max(ans, main) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN V...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
import sys input = sys.stdin.readline n, x = list(map(int, input().split())) A = list(map(int, input().split())) SUM = [0] for a in A: SUM.append(SUM[-1] + a) MAXLIST = [SUM[0]] MINLIST = [SUM[0]] for i in range(1, n + 1): MAXLIST.append(max(MAXLIST[-1], SUM[i])) MINLIST.append(min(MINLIST[-1], SUM[i])) MA...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER B...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
N, X = map(int, input().split()) a = list(map(int, input().split())) dp = [([0] * 3) for i in range(N + 1)] ans = 0 for i in range(N): dp[i + 1][0] = max(0, dp[i][0] + a[i]) dp[i + 1][1] = max(0, dp[i][1] + a[i] * X, dp[i][0] + a[i] * X) dp[i + 1][2] = max(0, dp[i][1] + a[i], dp[i][2] + a[i]) ans = max(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) a = list(map(int, input().split())) inf = -(2**64) dp = [[[inf for _ in range(3)] for _ in range(3)] for _ in range(n + 1)] dp[0][0][0] = 0 for i in range(n + 1): for j in range(3): for k in range(3): if k < 2: dp[i][j][k + 1] = max(dp[i][j][k + 1...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BI...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def find(A, x): maxi, c1, c2, c3 = 0, 0, 0, 0 for i in range(0, len(A)): c11 = max([c1, 0]) + A[i] c22 = max([c1, c2, 0]) + A[i] * x c33 = max([c2, c3, 0]) + A[i] c1, c2, c3 = c11, c22, c33 maxi = max([maxi, c1, c2, c3]) return maxi inp = lambda cast=int: list(map(c...
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR LIST VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR LIST VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
l = input().split() n = int(l[0]) x = int(l[1]) l = input().split() li = [int(i) for i in l] right = [(0) for i in range(n)] left = [(0) for i in range(n)] pref = [(0) for i in range(n)] pref[0] = li[0] for i in range(1, n): left[i] = max(0, li[i - 1] + left[i - 1]) pref[i] = pref[i - 1] + li[i] for i in range(...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) arr = [int(x) for x in input().split()] dp = [[(0) for i in range(3)] for j in range(n)] for i in range(n): dp[i][0] = max(0, arr[i]) dp[i][1] = max(0, arr[i]) dp[i][2] = max(0, arr[i] * x) if i == 0: continue dp[i][0] = max(dp[i][0], arr[i] + dp[i - 1][0]) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VA...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) l = list(map(int, input().split())) not_used = [(0) for k in range(n + 1)] current = [(0) for k in range(n + 1)] used = [(0) for k in range(n + 1)] globalMax = 0 for k in range(n): not_used[k + 1] = max(not_used[k], 0) + l[k] current[k + 1] = max(max(not_used[k], current[k]), 0)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CAL...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
d1, d2, d3, d4 = 0, 0, 0, 0 e1, e2, e3, e4 = 0, 0, 0, 0 n, x = map(int, input().split()) A = list(map(int, input().split())) + [0] for a in A: e1 = max(a, d1 + a) e2 = max(x * a, d1 + x * a, d2 + x * a) e3 = max(e1, d2 + a, d3 + a) e4 = max(d1, d2, d3, d4, a) d1, d2, d3, d4 = e1, e2, e3, e4 print(d4...
ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CAL...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) a = list(map(int, input().split())) def solve(n, x, a): s = [a[0]] * n left = [max(a[0], 0)] * n right = [max(a[-1], 0)] * n for i in range(1, n): left[i] = max(left[i - 1] + a[i], a[i], 0) s[i] = s[i - 1] + a[i] for i in range(n - 2, -1, -1): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VA...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
N, X = map(int, input().split()) ans = 0 for i, x in enumerate(map(int, input().split())): if i == 0: dp = max(0, x), max(0, x * X), max(0, x) else: dp = ( max(0, dp[0] + x), max(0, dp[1] + x * X, dp[0] + x * X), max(0, dp[2] + x, dp[1] + x), ) ans...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VA...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
N, X = map(int, input().split()) A = [int(a) for a in input().split()] dp = [([0] * 4) for _ in range(N + 1)] for i in range(1, N + 1): dp[i][0] = max(dp[i - 1][0] + A[i - 1], 0) dp[i][1] = max(dp[i - 1][1] + A[i - 1] * X, dp[i][0]) dp[i][2] = max(dp[i - 1][2] + A[i - 1], dp[i][1]) dp[i][3] = max(dp[i -...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def maxBeauty(): dp = [[(0) for i in range(3)] for j in range(n)] dp[0][0] = max(a[0], 0) dp[0][1] = max(a[0] * x, 0) dp[0][2] = max(a[0], 0) ans = 0 ans = max([ans, dp[0][0], dp[0][1], dp[0][2]]) for i in range(1, n): dp[i][0] = max(dp[i - 1][0] + a[i], 0) dp[i][1] = max(max...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR NUMBER N...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, m = (int(x) for x in input().split()) multipliers = [1] * 3 multipliers[1] = m arr = [int(x) for x in input().split()] dp = [[(0) for j in range(3)] for i in range(n + 1)] for i in range(n): for j in range(len(multipliers)): dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + arr[i] * multipliers[j]) if ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VA...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) A = list(map(int, input().split())) DP = [([0] * 3) for _ in range(n + 1)] ans = 0 for i in range(1, n + 1): DP[i][0] = max(DP[i - 1][0] + A[i - 1], A[i - 1]) DP[i][1] = max( DP[i - 1][0] + A[i - 1] * x, DP[i - 1][1] + A[i - 1] * x, A[i - 1] * x ) DP[i][2] = max(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
import sys input = sys.stdin.readline n, x = map(int, input().split()) a = list(map(int, input().split())) INF = 10**18 dp = [[([-INF] * 3) for i in range(3)] for j in range(n + 1)] dp[0][0][0] = 0 for i in range(n + 1): for j in range(3): for k in range(3): if k < 2: dp[i][j][k...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) lis = list(map(int, input().split())) dp = dict() mx = mx = float("-inf") dp[0, 1, 0] = lis[0] dp[0, 1, 1] = x * lis[0] dp[0, 0, 0] = 0 mx = max(mx, max(dp[0, 1, 0], dp[0, 1, 1])) for i in range(1, n): dp[i, 1, 1] = max(x * lis[i], x * lis[i] + max(dp[i - 1, 1, 0], dp[i - 1, 1, 1]))...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) dp1 = [0] * n dp2 = [0] * n dp0 = [0] * n ans = 0 v = [int(i) for i in input().split()] dp0[0] = max(0, v[0]) dp1[0] = v[0] * x i = 0 ans = max(ans, dp1[i], dp2[i], dp0[i]) for i in range(1, n): dp0[i] = max(0, dp0[i - 1] + v[i]) dp1[i] = max(dp1[i - 1] + v[i] * x, dp0[i - 1] + ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def solve(): n, x = list(map(int, input().split())) a = [0] + list(map(int, input().split())) max_val = 0 dp1 = [0] * (n + 1) for i in range(1, n + 1): dp1[i] = max(dp1[i - 1] + a[i], a[i]) max_val = max(max_val, dp1[i]) dp2 = [0] * (n + 1) for i in range(1, n + 1): d...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR B...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
import sys def main(): print = out.append n, x = get_list() li = get_list() ans = best1 = best2 = best3 = 0 for a in li: best3 = max(0, best1 + a, best2 + a, best3 + a) best2 = max(0, best1 + x * a, best2 + x * a) best1 = max(0, best1 + a) ans = max(ans, best1, best...
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) a = list(map(int, input().split())) b = [([0] * 3) for i in range(n)] for i in range(n): if i == 0: b[i][0] = max(a[i], 0) b[i][1] = a[i] * x b[i][2] = max(b[i][1], a[i]) else: b[i][0] = max(b[i - 1][0] + a[i], 0) b[i][1] = max(b[i - 1][1]...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIG...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def main(): n, x = list(map(int, input().split())) l = list(map(int, input().split())) ans = a = b = c = 0 for i in l: c = max(0, i, a + i, b + i, c + i) b = max(0, i * x, a + i * x, b + i * x) a = max(0, i, a + i) ans = max(0, ans, a, b, c) print(ans) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) a = list(map(int, input().split())) dp = [[(0) for i in range(3)] for j in range(n + 1)] a = [0] + a res = 0 for i in range(1, n + 1): dp[i][0] = max(0, dp[i - 1][0] + a[i], a[i]) dp[i][1] = max(0, dp[i - 1][0] + a[i] * x, dp[i - 1][1] + a[i] * x, a[i] * x) dp[i][2] = max( ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUM...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
from sys import stdin, stdout nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) def fn(pos, state): if pos < 0: return 0 if state == 2: ans = max(a[pos], x * a[pos] + fn(pos - 1, 1), a[pos] + fn(pos - 1, 2)) elif state == 1: ans = max(a[pos], x * a[pos] + f...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMB...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def solve(): N, X = map(int, input().split()) A = [int(k) for k in input().split()] ans = 0 cur_max1 = 0 cur_max2 = 0 cur_max3 = 0 for a in A: cur_max1 = max(a, cur_max1 + a) cur_max2 = max(a * X, a * X + cur_max2, cur_max1) cur_max3 = max(a, cur_max3 + a, cur_max2) ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) cur1 = cur2 = cur = res = 0 for a in map(int, input().split()): cur1 = max(cur1 + a, 0) cur2 = max(cur2 + a * x, cur1) cur = max(cur + a, cur2) res = max(res, cur) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, m = map(int, input().split()) dp = [[([-9487948794879487] * 3) for j in range(3)] for i in range(n + 1)] nums = list(map(int, input().split())) dp[0][0][0] = 0 dp[0][1][0] = 0 for i in range(1, n + 1): dp[i][0][0] = dp[i - 1][0][0] dp[i][1][0] = max(dp[i - 1][1][0] + nums[i - 1], dp[i - 1][0][0] + nums[i - 1...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VA...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = list(map(int, input().split())) a = list(map(int, input().split())) a_mult_x = [0] * n for i in range(n): a_mult_x[i] = a[i] * x dp = [] dp.append([0] * n) dp.append([0] * n) dp.append([0] * n) if a[0] > 0: dp[0][0] = a[0] dp[2][0] = a[0] if a_mult_x[0] > 0: dp[1][0] = a_mult_x[0] for i in range(...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR BIN_OP LIST...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def solve(N, X, A): ans = best1 = best2 = best3 = 0 for a in A: best3 = max(0, a, best1 + a, best2 + a, best3 + a) best2 = max(0, X * a, best1 + X * a, best2 + X * a) best1 = max(0, a, best1 + a) ans = max(ans, best1, best2, best3) return ans N, X = [int(x) for x in input()...
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR V...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, m = input().split(" ") n = int(n) m = int(m) arr = input().split(" ") arr = [0] + [int(x) for x in arr] dp = [([0] * (len(arr) + 1)) for i in range(3)] ans = 0 for i in range(1, len(arr)): dp[0][i] = max(0, dp[0][i - 1]) + arr[i] dp[1][i] = max(dp[0][i - 1], max(0, dp[1][i - 1])) + arr[i] * m dp[2][i] = ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def go(): n, x = map(int, input().split(" ")) a = [int(i) for i in input().split(" ")] cur1 = cur2 = cur = maximum = 0 for i in range(len(a)): cur1 = max(0, cur1 + a[i]) cur2 = max(cur1, cur2 + x * a[i]) cur = max(cur + a[i], cur2) maximum = max(maximum, cur) return m...
FUNC_DEF 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 VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASS...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def beauty(arr, x): d = [ [[(-float("inf")) for k in range(3)] for j in range(3)] for i in range(len(arr) + 1) ] d[0][0][0] = 0 ans = 0 for i in range(len(arr)): for j in range(3): for k in range(3): if k < 2: d[i][j][k + 1] = m...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) a = list(map(int, input().split())) dp = [[(0) for _ in range(n + 1)] for _ in range(3)] ans = 0 for i in range(n): dp[0][i + 1] = max(0, dp[0][i] + a[i]) dp[1][i + 1] = max(dp[0][i], dp[1][i]) + a[i] * x dp[2][i + 1] = max(dp[0][i], dp[1][i], dp[2][i]) + a[i] ans = max(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBE...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) a = [int(i) for i in input().split()] a.insert(0, 0) pref = [0] dp = [[0, 0, 0] for _ in range(n + 1)] for i in range(1, n + 1): dp[i][0] = max(0, dp[i - 1][0] + a[i]) dp[i][1] = max(0, dp[i - 1][0] + x * a[i], dp[i - 1][1] + x * a[i]) dp[i][2] = max(0, dp[i][0], dp[i][1], d...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CAL...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
def main(): n, x = map(int, input().split()) a = list(map(int, input().split())) dp = [[0, 0, 0] for _ in range(n)] dp[0][0] = max(0, a[0]) dp[0][1] = max(0, x * a[0]) answer = max(dp[0]) for i in range(1, n): dp[i][0] = max(dp[i - 1][0] + a[i], a[i]) dp[i][1] = max(dp[i - 1]...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASS...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
IN = input().split() n = int(IN[0]) x = int(IN[1]) A = input().split() dp = [0] * 3 for i in range(0, 3): dp[i] = [0] * (n + 1) ans = 0 for i in range(0, n): idx = i + 1 cur = int(A[i]) dp[0][idx] = max(0, dp[0][idx - 1] + cur) dp[1][idx] = max(0, max(dp[0][idx - 1], dp[1][idx - 1]) + cur * x) d...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR AS...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
N, X = list(map(int, input().split())) a_list = list(map(int, input().split())) dp = [([0] * 5) for _ in range(303030)] for i in range(N): a = a_list[i] dp[i + 1][0] = 0 dp[i + 1][1] = max(dp[i][1] + a, dp[i + 1][0]) dp[i + 1][2] = max(dp[i][2] + a * X, dp[i + 1][1]) dp[i + 1][3] = max(dp[i][3] + a,...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUM...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, m = map(int, input().split()) a = list(map(int, input().split())) def factiry(arr, mul): curMax, mulMax, gloMax, cur = 0, 0, 0, 0 for i in range(n): curMax = max(arr[i] + curMax, 0) mulMax = max(mulMax + arr[i] * mul, curMax) cur = max(cur + arr[i], mulMax) gloMax = max(gloM...
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 FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, k = map(int, input().split()) l = [*map(int, input().split())] dp = [([0] * 3) for i in range(n)] for i in range(n): for j in range(3): dp[i][j] = float("inf") ans = 0 for i in range(n): if i == 0: dp[i][0] = max(l[i], 0) dp[i][1] = max(l[i] * k, 0) dp[i][2] = max(l[i], 0) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = [int(x) for x in input().split()] data = [int(x) for x in input().split()] dp = [[(0) for _ in range(3)] for _ in range(n + 1)] for i, v in enumerate(data): i += 1 dp[i][0] = max(dp[i - 1][0] + v, v) dp[i][1] = max(dp[i - 1][0] + v * x, v * x, dp[i - 1][1] + v * x) dp[i][2] = max(dp[i - 1][1] + v...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR AS...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = list(map(int, input().split())) l = list(map(int, input().split())) b = [0] * n f = [0] * n pref = [0] * n pref[0] = l[0] for i in range(1, n): pref[i] = pref[i - 1] + l[i] b[0] = x * l[0] mini = 0 for i in range(1, n): mini = min(mini, pref[i - 1]) b[i] = x * l[i] + max(b[i - 1], pref[i - 1] - mini)...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = [int(i) for i in input().split()] A = [int(i) for i in input().split()] dp = [[(-(10**18)) for i in range(5)] for j in range(len(A))] for i in range(n - 1, -1, -1): if 1: nxt = [0, 0, 0, 0, 0] if i != n - 1: nxt = dp[i + 1] coeff = [0, 1, x, 1, 0] for j in range(5)...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER N...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
n, x = map(int, input().split()) v = list(map(int, input().split())) def DP_Beautiful_array(v, n, x): dp = [([0] * 3) for i in range(n)] dp[0][0] = v[0] dp[0][1] = x * v[0] answer = max(0, max(v[0], x * v[0])) for i in range(1, n, 1): dp[i][0] = max(v[i], v[i] + dp[i - 1][0]) dp[i]...
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 FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
import sys def input(): return sys.stdin.readline().rstrip() DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] INF = 1 << 64 def main(): n, x = map(int, input().split()) a = list(map(int, input().split())) A = [0] + a.copy() revA = [0] + a.copy()[::-1] b = [-INF] * n revb = [-INF] * n ans =...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_C...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
import sys input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ out = [] get_int = lambda: int(input()) get_list = lambda: list(map(int, input().split())) def main(): n, x = get_list() li = get_list() u_before = [0] * n not_u = [0] * n being_u = [0] * n u_before[0], not_u[0], ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR A...
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
import sys input = sys.stdin.readline n, x = map(int, input().split()) A = list(map(int, input().split())) DP0 = [0] * (n + 1) DP1 = [0] * (n + 1) DP2 = [0] * (n + 1) for i in range(n): DP0[i] = max(DP0[i - 1] + A[i], A[i], 0) DP1[i] = max(DP0[i - 1] + A[i] * x, DP1[i - 1] + A[i] * x, DP0[i]) DP2[i] = max(...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSI...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
n = int(input()) INF = -1 arr = [0] * n d = [0] * 201 l = list(map(int, input().split())) e = list(map(int, input().split())) s = 0 for i in range(n): arr[i] = l[i], e[i] s += e[i] d[e[i]] += 1 l = [] e = [] ans = [INF] * 3 ans[2] = 10**10 p = arr[-1][0] k = [0, 0] arr.sort() arr = [(-1, -1)] + arr e = 0 c ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
f = lambda: map(int, input().split()) k, n = 1, f() s = sorted(zip(f(), f()), key=lambda q: q[0]) t = [0] * 201 for l, d in s: t[d] += 1 j = [i for i in range(201) if t[i]] j.reverse() S = sum(i * t[i] for i in j) L, D = s.pop() t[D] -= 1 s.reverse() s.append((0, 0)) m = 0 for l, d in s: if l < L: L = l...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CA...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
f = lambda: list(map(int, input().split())) n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1]) for L, d in s: k, D = p.get(L, (-1, 0)) p[L] = k + 1, D + d for L, (k, D) in list(p.items()): if k: for l, d in s: if l < L: D += d k -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR DICT NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR VAR VAR FUNC_CALL ...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
def read_data(): n = int(input()) Ls = list(map(int, input().split())) Ds = list(map(int, input().split())) return n, Ls, Ds def solve(n, Ls, Ds): freqD = [0] * 201 for d in Ds: freqD[d] += 1 LDs = list(zip(Ls, Ds)) LDs.sort(reverse=True) prevL = 0 ni = 0 record = f...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
def main(): _, dd, res = input(), {}, 0 he = list(zip(list(map(int, input().split())), list(map(int, input().split())))) for h, e in he: le, x = dd.get(h, (-1, 0)) dd[h] = le + 1, x + e he.sort(key=lambda _: _[1], reverse=True) for h, (le, x) in list(dd.items()): if le: ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR DICT NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
n = int(input()) lengths = list(map(int, input().split())) costs = list(map(int, input().split())) sum = 0 length_to_sum = {} length_to_count = {} cost_to_lengths = {} for i in range(n): length, cost = lengths[i], costs[i] sum += cost length_to_sum[length] = length_to_sum.setdefault(length, 0) + cost le...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR B...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
from sys import stdin, stdout def main(): n = int(stdin.readline()) leg = [int(_) for _ in stdin.readline().split()] d = [int(_) for _ in stdin.readline().split()] pairedLD = [] for x, y in zip(leg, d): pairedLD.append((x, y)) pairedLD = sorted(pairedLD) legSet = set() suffixSu...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR AS...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
def buscaEnergia(perna, qtd): total = 0 if qtd == 0: return total for i in range(len(d) - 1, -1, -1): for v in d[i]: if v < perna: qtd -= 1 total += i else: break if qtd == 0: break if...
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CAL...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
n = int(input()) legs = list(zip(list(map(int, input().split())), list(map(int, input().split())))) legs.sort(key=lambda x: x[1], reverse=True) cnt = {} s = 0 for i in range(n): s += legs[i][1] if legs[i][0] not in cnt: cnt[legs[i][0]] = [1, legs[i][1]] else: cnt[legs[i][0]][0] += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUM...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
def increment(d, key, energy): if key in d.keys(): d[key][0] += 1 d[key][1] += energy else: d[key] = [1, energy] legs = int(input()) lengths = list(map(int, input().split())) energies = list(map(int, input().split())) pairsEL = [] for x in range(legs): pairsEL.append([energies[x], ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXP...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) arr = list(zip(a, b)) d, res = {}, 0 for i, j in arr: f, x = d.get(i, (-1, 0)) d[i] = f + 1, x + j arr.sort(key=lambda x: x[1], reverse=True) for it, (f, x) in d.items(): if not f: res = max(x, res) cont...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR DICT NUMBER FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} —...
MAX_D = 201 n = int(input()) l = list(map(int, input().split())) d = list(map(int, input().split())) legs = sorted(list(zip(l, d))) d_suffix = [legs[0][1]] for i in range(1, n): d_suffix.append(d_suffix[-1] + legs[i][1]) ans = d_suffix[-1] cnt = {} left = 0 right = 0 while left < n: while right < n and legs[lef...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR E...
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
import sys n = int(sys.stdin.readline()) valores = [sys.stdin.readline().strip().split(" ") for _ in range(n)] tmp = [0] * n stack = [] valores.sort(key=lambda x: (int(x[1]), int(x[0])), reverse=True) for i in range(n): while len(stack) > 0 and int(valores[stack[-1]][0]) >= int(valores[i][1]): stack.pop() ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR...
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
from sys import stdin n = int(input()) x, ans, sum = [([0] * 3) for i in range(n)], 0, 0 d = [] for i in range(n): x[i][1], x[i][0], x[i][2] = map(int, stdin.readline().split()) x.sort() for i in range(n - 1, -1, -1): while len(d) > 0 and d[len(d) - 1][1] >= x[i][0]: sum -= d[len(d) - 1][2] d.p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBE...
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
aux = [(9000000000.0, 0, 0)] n = int(input()) for i in range(n): a, b, h = map(int, input().split()) aux.append((b, a, h)) aux.sort(reverse=True) s, p = [0], [0] * (n + 1) for i in range(1, n + 1): while aux[s[-1]][1] >= aux[i][0]: s.pop() p[i] = p[s[-1]] + aux[i][2] s.append(i) print(max(p)...
ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP ...
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
def ri(): return map(int, input().split()) n = int(input()) r = [] T = [] maxt = -1 for i in range(n): r.append(list(ri())) r.sort(key=lambda e: (e[1], e[0])) T.append([r[0][2], r[0][1]]) for i in range(1, n): tmp = r[i][2] l = len(T) for j in range(l): if r[i][0] >= T[-1][1]: ...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER...
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strang...
n = int(input()) d = [] for i in range(n): a, b, h = map(int, input().split()) d.append((b, a, h)) d.sort() ht = d[len(d) - 1][2] ans = ht s = [] s.append(d[len(d) - 1]) for i in range(n - 2, -1, -1): while s and d[i][0] <= s[len(s) - 1][1]: ht -= s.pop()[2] s.append(d[i]) ht += d[i][2] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR...
You are given a book with $n$ chapters. Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list. Currently you don't understand any of the chapters. You are goi...
import sys input = sys.stdin.readline def solve(): n = int(input()) arr = [list(map(int, input().split())) for _ in range(n)] graph = [[] for _ in range(n)] incoming = [0] * n vals = [1] * n for i in range(n): for j in range(1, len(arr[i])): incoming[i] += 1 gr...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ...
You are given a book with $n$ chapters. Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list. Currently you don't understand any of the chapters. You are goi...
t = int(input()) while t: n = int(input()) ct = [1] * n pre_req = [0] * n dt = {i: [] for i in range(n)} queue = [] for j in range(n): a = list(map(int, input().split())) for i in range(1, a[0] + 1): dt[a[i] - 1].append(j) pre_req[j] = a[0] if a[0] == ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_...
You are given a book with $n$ chapters. Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list. Currently you don't understand any of the chapters. You are goi...
t = int(input()) for i in range(t): n = int(input()) l = [1] * n d = {i: [] for i in range(n)} q = [] m = [0] * n for j in range(n): a = [*map(int, input().split())] for i in range(1, a[0] + 1): d[a[i] - 1].append(j) m[j] = a[0] if a[0] == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VA...
You are given a book with $n$ chapters. Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list. Currently you don't understand any of the chapters. You are goi...
def solve(_num=0): n = int(input()) chapters = [] c___deps = [[] for _ in range(n)] for i in range(n): c = [(int(x) - 1) for x in input().split()] c.pop(0) for neigh in c: c___deps[neigh].append(i) chapters.append(c) stack = [] c___rnr = [(0) for _ in ...
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR...
You are given a book with $n$ chapters. Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list. Currently you don't understand any of the chapters. You are goi...
def func2(datalist, n): fished = [0] * (n + 1) sid = 1 eid = 1 xlist = [[]] children = [[] for i in range(n + 1)] xn = 0 for i in range(1, n + 1): if datalist[i][0] == 0: fished[eid] = i eid += 1 xlist.append([1, 0]) xn += 1 els...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUM...
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represent the number of such indexes k, that xk is divisible by p. The answe...
import sys input = sys.stdin.buffer.readline n = int(input()) x = list(map(int, input().split())) mx = max(x) hf = [i for i in range(mx + 1)] p = 2 while p * p <= mx: if hf[p] == p: for m in range(p * p, mx + 1, p): hf[m] = p p += 1 count = [0] * (mx + 1) for e in x: while e > 1: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, A, R, C, K, Q, q_i, q_j): dp = [[(0) for i in range(C)] for i in range(R)] dp[0][0] = A[0][0] for i in range(1, C): dp[0][i] = dp[0][i - 1] + A[0][i] for i in range(1, R): dp[i][0] = dp[i - 1][0] + A[i][0] for i...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): dp = [[(0) for k in range(C)] for k in range(R)] dp[0][0] = M[0][0] for i in range(1, R): dp[i][0] = dp[i - 1][0] + M[i][0] for j in range(1, C): dp[0][j] = dp[0][j - 1] + M[0][j - 1] f...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): dp = [([0] * (C + 1)) for _ in range(R + 1)] for i in range(R): pres = 0 for j in range(C): pres += M[i][j] dp[i + 1][j + 1] = pres + dp[i][j + 1] ans = [] for x...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR V...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): myDP = [([0] * (C + 1)) for i in range(R + 1)] for i in range(R): for j in range(C): myDP[i + 1][j + 1] = ( M[i][j] + myDP[i + 1][j] + myDP[i][j + 1] - myDP[i][j] ) ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF RETURN BIN_O...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): dp = [([0] * (C + 1)) for _ in range(R + 1)] for i in range(R): for j in range(C): dp[i + 1][j + 1] = M[i][j] + dp[i + 1][j] + dp[i][j + 1] - dp[i][j] def sumarea(r2, c2, r1, c1): retu...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF RETURN BIN_O...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): row = [] rsum = 0 for x in M[0]: rsum += x row += [rsum] grid = [row + [0]] for i in range(1, R): row = [] rsum = 0 for j, x in enumerate(M[i]): ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR VAR LIST VAR ASSIGN VAR LIST BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR LIST BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR LIST BIN_OP VAR LIST NUMBER V...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): for i in range(1, R): M[i][0] += M[i - 1][0] for i in range(1, C): M[0][i] += M[0][i - 1] for i in range(1, R): for j in range(1, C): M[i][j] = M[i - 1][j] + M[i][j - 1] - M...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP ...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): l1 = [] l2 = [([0] * (C + 1)) for _ in range(R + 1)] i = 1 while i <= R: j = 1 while j <= C: l2[i][j] = ( M[i - 1][j - 1] + l2[i - 1][j] + l2[i][j - 1] - l2[...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR B...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, matrix, R, C, K, Q, q_i, q_j): countDP = [[(0) for x in range(C)] for x in range(R)] countDP[0][0] = matrix[0][0] final = [] for i in range(1, R): countDP[i][0] = countDP[i - 1][0] + matrix[i][0] for j in range(1, C): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER B...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, arr, m, n, k, q, q_i, q_j): def get_count(i1, j1, i2, j2): if i1 == 0 and j1 == 0: return count_arr[i2][j2] if i1 == 0: return count_arr[i2][j2] - count_arr[i2][j1 - 1] if j1 == 0: r...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BI...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Prefix: def __init__(self, grid): self.numRows = len(grid) self.numCols = len(grid[0]) self.prefix = [ [(0) for cell in range(self.numCols + 1)] for row in range(self.numRows + 1) ] self.build(grid) def build(self, grid): for row in range(1, se...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR B...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): query_coordinates = zip(q_i, q_j) largest_sq = [(0) for i in range(Q)] subarr_sum_mat = [[(0) for j in range(C)] for i in range(R)] subarr_sum_mat[0][0] = M[0][0] for i in range(R): pref_sum = 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_C...
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {...
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): psum = [[(0) for _ in range(C)] for _ in range(R)] psum[0][0] = M[0][0] for i in range(1, C): psum[0][i] = psum[0][i - 1] + M[0][i] for i in range(1, R): psum[i][0] = psum[i - 1][0] + M[i][0] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER...