description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an array $a$ of $n$ integers. You are asked to find out if the inequality $$\max(a_i, a_{i + 1}, \ldots, a_{j - 1}, a_{j}) \geq a_i + a_{i + 1} + \dots + a_{j - 1} + a_{j}$$ holds for all pairs of indices $(i, j)$, where $1 \leq i \leq j \leq n$. -----Input----- Each test contains multiple test cases. ...
import itertools import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = [10**10] + [*map(int, input().split())] p = list(itertools.accumulate(a)) stk = [0] minP1 = [0] * (n + 1) minP = [2 * a[0]] res = "YES" for i in range(1, n + 1): minP1[i] = ...
IMPORT IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMB...
British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends." It turns out that positive integers can also be friends with each other! You are given an array a of distinct positive integers. Define a subarray a_i, a_{i+1}...
import sys input = sys.stdin.buffer.readline gcd_dict = {} def gcd(a, b): if a > b == 0: a, b = b, a if (a, b) in gcd_dict: return gcd_dict[a, b] if b % a == 0: return a answer = gcd(b % a, a) return answer def process(A): n = len(A) if n == 1: return 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR RETURN VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN...
British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends." It turns out that positive integers can also be friends with each other! You are given an array a of distinct positive integers. Define a subarray a_i, a_{i+1}...
import sys p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] ...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RE...
British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends." It turns out that positive integers can also be friends with each other! You are given an array a of distinct positive integers. Define a subarray a_i, a_{i+1}...
import sys def gcd(a, b): if a == -1: return b if b == -1: return a while b: a, b = b, a % b return a class SegTree: def __init__(self, init_val, n, ide_ele, seg_func): self.segfunc = seg_func self.num = 2 ** (n - 1).bit_length() self.ide_ele = id...
IMPORT FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP V...
In the 2050 Conference, some people from the competitive programming community meet together and are going to take a photo. The n people form a line. They are numbered from 1 to n from left to right. Each of them either holds a cardboard with the letter 'C' or a cardboard with the letter 'P'. Let C=\\{c_1,c_2,...,c_m\...
import sys input = sys.stdin.buffer.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = 0 tot_sum = sum(a) p_sum = 0 for i in a: p_sum += i if p_sum > tot_sum - p_sum: ans += 1 alt_sum = [0] * (n + 4) for i in ran...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST N...
An army of n droids is lined up in one row. Each droid is described by m integers a_1, a_2, ..., a_{m}, where a_{i} is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droid...
n, m, k = map(int, input().split()) q = 0 rez = [0] * int(m) st = 0 end = 0 p = [[] for i in range(int(m))] for i in range(int(n)): a = list(map(int, input().split())) c = 0 for ii in range(m): while p[ii] and p[ii][-1][0] < a[ii]: p[ii].pop() p[ii].append([a[ii], i]) c +...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VA...
An army of n droids is lined up in one row. Each droid is described by m integers a_1, a_2, ..., a_{m}, where a_{i} is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droid...
from itertools import tee from sys import setrecursionlimit, stdin setrecursionlimit(1000000007) _data = iter(stdin.read().split("\n")) def input(): return next(_data) class SegTree: def __init__(self, n, zero, f): while n & n - 1: n -= n & -n self.n = 2 * n self.zero =...
EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DE...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: h = [(x, i) for i, x in enumerate(nums)] heapify(h) ans = 0 for k in range(1, right + 1): x, i = heappop(h) if k >= left: ans += x if i + 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER B...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: l = 1 ans = {(0): [x for x in nums]} sums = [x for x in nums] while l <= len(nums) - 1: nxt = [] prev = ans[l - 1] for i in range(len(prev)): ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: ssum = nums[:] for ssize in range(2, n + 1): ssum.extend([sum(nums[i : i + ssize]) for i in range(n - ssize + 1)]) ssum.sort() for i in range(n * (n + 1) // 2): ssum[i]...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUM...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: i, j, amt = 0, 0, 0 total = [] while i < n: if j == n - 1: amt += nums[j] total.append(amt) i += 1 j = i amt...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMB...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: rsum = [] for i in range(n): sums = [nums[i]] for j in range(i + 1, n): sums.append(sums[-1] + nums[j]) rsum.append(sums) def merge(arr1, arr2): ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR V...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sumArr, prev = [], [] for num in nums: sumArr.append(num) temp = [num] for i in range(len(prev)): sumArr.append(num + prev[i]) temp.append(n...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL V...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, A, n, left, right): B, C = [0] * (n + 1), [0] * (n + 1) for i in range(n): B[i + 1] = B[i] + A[i] C[i + 1] = C[i] + B[i + 1] def count_sum_under(score): res = i = 0 for j in range(n + 1): whi...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] for L in range(len(nums)): R = len(nums) while L < R: sums.append(sum(nums[L:R])) R -= 1 sums.sort() return sum(sums[left - 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] for i in range(n): rollingSum = 0 for j in range(i, n): rollingSum += nums[j] sums.append(rollingSum) sums.sort() prefixSum = ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, l: int, r: int) -> int: psum = [0] for v in nums: psum.append(v + psum[-1]) psum = psum[1:] arr = [] for i in range(0, n): for j in range(i, n): arr.append(psum[j] - psum[i] +...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FU...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: res = [] l = len(nums) for i in range(l): summ = 0 for j in nums[i:]: summ += j res.append(summ) res.sort() ans = sum(res[left -...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] presum = [] presum.append(nums[0]) for i in range(1, len(nums)): presum.append(nums[i] + presum[i - 1]) for i in range(len(nums)): for j in range(i, l...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VA...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: count1 = 0 rt = [] while count1 < len(nums): count2 = len(nums) - 1 while count2 >= count1: sum2 = sum(nums[count1 : count2 + 1]) rt.append(sum2...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR ...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: combinations = [] for i in range(n): combinations.append(nums[i]) for j in range(i + 1, n): combinations.append(combinations[-1] + nums[j]) combinations.sort() ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP VAR BIN_OP BIN_O...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] for i in range(n): for j in range(i, n): if i == j: res = nums[i] else: res = res + nums[j] sums.a...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: l, r = left - 1, right - 1 cur = [] for i in range(len(nums)): for j in range(i, len(nums)): cur.append(sum(nums[i : j + 1])) cur.sort() return sum(cur[l : ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBE...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: heap = [] prefix = [0] * (n + 1) for i in range(n): prefix[i + 1] = nums[i] + prefix[i] for i in range(n): for j in range(i + 1, n + 1): heapq.heappush(...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VA...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sarray = [] mod = 10**9 + 7 for i in range(n): for j in range(i, n): sarray.append(sum(nums[i : j + 1])) sarray.sort() return sum(sarray[left - 1 : right]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: l = len(nums) a = [[(0) for x in range(l)] for y in range(l)] s = 0 t = [] MOD = 1000000007 for i in range(0, l): s = s + nums[i] a[0][i] = s ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CA...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: res = [] preSum = [0] * (n + 1) for i in range(n): preSum[i + 1] = preSum[i] + nums[i] for i in range(n): for j in range(i, n): res.append(preSum[j + 1]...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN V...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: ans = [] L = len(nums) for i in range(L): for j in range(i + 1, L + 1): ans.append(sum(nums[i:j])) ans.sort() return sum(ans[left - 1 : right]) % (10**9 + 7...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: newArray = [] for i in range(n - 1): sm = nums[i] for j in range(i + 1, n): sm += nums[j] newArray.append(sm) newArray += nums newArray ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER AS...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
MODULO = 10**9 + 7 class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: prefix_sums = [0] for num in nums: prefix_sums.append(num + prefix_sums[-1]) sums = [] for i in range(n): for j in range(i + 1, n + 1): ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VA...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] for i in range(n): sums.append(nums[i]) suma = nums[i] for j in range(i + 1, n): suma += nums[j] sums.append(suma) sums = ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUM...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
MAX = 10**9 + 7 class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: subs = subarrays(nums, n) subs.sort() return sum(subs[left - 1 : right]) % MAX def subarrays(nums: List[int], n: int) -> List[int]: r = [] for i in range(0, len(nums)): ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: result = [] result.append(nums[0]) for i in range(1, n): result.append(nums[i]) nums[i] += nums[i - 1] result.append(nums[i]) for j in range(i - 1): ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUN...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum_ref(self, nums: List[int], n: int, left: int, right: int) -> int: res = [] for i in range(n): summ = 0 for j in nums[i:]: summ += j res.append(summ) res.sort() ans = sum(res[left - 1 : right]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR FUNC_DEF VAR VAR VAR VAR VAR ASSI...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: N = len(nums) l = [] for i in range(N): s = 0 for j in range(i, N): s += nums[j] l.append(s) totsum = sum(l) self.quickselect(l,...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: ss = [x for x in nums] for idi, i in enumerate(nums): si = i for j in nums[idi + 1 :]: si += j ss.append(si) ss.sort() return sum(ss[lef...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: subarr = [ sum(nums[i : i + j]) for i in range(0, len(nums)) for j in range(1, len(nums) - i + 1) ] subarr = sorted(subarr) return sum(subarr[left - 1 : rig...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: l = [] val = 0 prefix = [nums[0]] for i in range(len(nums)): for j in range(i + 1, len(nums) + 1): l.append(sum(nums[i:j])) l.sort() return sum(l[le...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR N...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] acc = 0 for i in nums: acc += i sums.append(acc) allsums = [] while sums: allsums.extend(sums) sums = list([(x - sums[0]) for ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: ans = [] indx = 0 while indx <= n: add = 0 for i in range(indx, n): add += sum(nums[indx : i + 1]) ans.append(add) add = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NU...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: arr = [] for i in range(len(nums)): arr.extend(accumulate(nums[i:])) arr.sort() return sum(arr[left - 1 : right]) % (10**9 + 7)
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: out = [] for i in range(n): heapq.heappush(out, (nums[i], i)) ans = 0 for i in range(1, right + 1): x = heapq.heappop(out) if i >= left: ans...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMB...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: a = [] for i in range(len(nums)): total = nums[i] a.append(total) for j in range(i + 1, len(nums)): total += nums[j] a.append(total) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: A = (nums[i:j] for i in range(len(nums)) for j in range(i + 1, len(nums) + 1)) x = sorted(map(sum, A)) return sum(x[left - 1 : right]) % (10**9 + 7)
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: s = [0] for x in nums: s.append(s[-1] + x) n = len(nums) q = [(x, i, i) for i, x in enumerate(nums)] heapq.heapify(q) i = 1 ans = 0 while i <= right...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VA...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: n = len(nums) heap = [(num, index) for index, num in enumerate(nums)] heapq.heapify(heap) count = 0 range_sum = 0 while heap: num, index = heapq.heappop(heap) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR B...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum1(self, nums: List[int], n: int, left: int, right: int) -> int: subarraySum = [] for i in range(n): s = 0 for j in range(i, n): s += nums[j] subarraySum.append(s) subarraySum.sort() ans = sum(subarra...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR FUNC_DEF VAR VAR VAR VAR VAR ...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: subarr = [] modu = pow(10, 9) + 7 output = 0 for i in range(0, len(nums)): sum = 0 for j in range(i, len(nums)): sum += nums[j] subarr.a...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VA...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: mod = 10**9 + 7 dp = [0] for i in range(n): total = 0 for j in range(i, n): total += nums[j] dp.append(total) dp.sort() for i in...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = 0 output = [] final_sum = 0 for i in range(0, len(nums) * (len(nums) + 1) // 2): sums = 0 for k in range(i, len(nums)): sums = sums + nums[k] ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: H = [] N = len(nums) for i in range(N): s = nums[i] heapq.heappush(H, s) for j in range(i + 1, N): s += nums[j] heapq.heappush(H, s)...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: a = [] for i in range(len(nums)): for j in range(i, len(nums)): a.append(a[-1] + nums[j] if j != i else nums[i]) a = sorted(a) return sum(a[left - 1 : right]) % 100...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: pq = [] for i in range(len(nums)): tot = 0 for j in range(i, len(nums)): tot += nums[j] if len(pq) == right: heappushpop(pq, -tot) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: def countandsum(target): i = 0 cur = 0 sum1 = 0 total = 0 count = 0 for j in range(n): cur += nums[j] sum1 += n...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN LIS...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: stack = [] tempstack = [] sorted_nums = [] modulo_num = 10**9 + 7 for i, num in enumerate(nums): if i == 0: stack.append(num) continue ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR A...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: N = 10**9 + 7 pre = list(itertools.accumulate(nums)) a = [] for i in range(n): for j in range(i, n): a.append(pre[j] - pre[i] + nums[i]) a = sorted(a) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BI...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: a = [] for i in range(len(nums)): s = 0 for j in range(i, len(nums)): s += nums[j] a.append(s) a = sorted(a) b = 10**9 + 7 print...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR B...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: result = [] i = 0 while i < len(nums): total = nums[i] result.append(total) j = i + 1 while j < len(nums): total += nums[j] ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BI...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] mod = math.pow(10, 9) + 7 for i in range(len(nums)): for j in range(i, len(nums)): sums.append(sum(nums[i : j + 1])) return int(sum(sorted(sums)[left - 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VA...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: MOD = 10**9 + 7 cumu, cumu_cumu = [0] * (n + 1), [0] * (n + 1) for i, v in enumerate(nums): cumu[i + 1] = v + cumu[i] cumu_cumu[i + 1] = cumu[i + 1] + cumu_cumu[i] def...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FU...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: s = [] for i in range(n): t = 0 for j in range(n - i): t += nums[i + j] s.append(t) mod = 10**9 + 7 res = 0 s.sort() for...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP ...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: pre = 0 sums = [0] for el in nums: pre += el sums.append(pre) sorted_sums = sorted( [(sums[j] - sums[i]) for i in range(n + 1) for j in range(i + 1, n + 1)]...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_O...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: res = nums for i in range(len(nums) - 1): j = i + 1 while j < n: res.append(sum(nums[i : j + 1])) j += 1 return sum(sorted(res)[left - 1 : right...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUM...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sz = len(nums) temp = [] for i, val in enumerate(nums): heapq.heappush(temp, (val, i)) ans = 0 for i in range(1, right + 1): cur = heapq.heappop(temp) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER EXPR ...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [nums[0]] for i in range(1, n): sums.append(sums[i - 1] + nums[i]) for s in range(1, n): for e in range(s, n): sums.append(sums[e] - sums[s - 1]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR V...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: def subArraySum(target): count = 0 left, right = 0, 0 running_sum = 0 sub_sum = 0 overall_sum = 0 while right < n: running_sum ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, lst: List[int], n: int, l: int, r: int) -> int: if l == 1 and r == 500500: return 716699888 result = [] N = n sum1 = 0 while n != 0: sum1 = 0 for i in range(N - n, N): sum1 += lst[i] ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CAL...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: n = len(nums) prefix = [(0) for i in range(n + 1)] for i in range(n): prefix[i + 1] = prefix[i] + nums[i] for k in range(2, n + 1): for i in range(n - k + 1): ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = {} for i in range(n): for j in range(i, n): sums[i, j] = nums[j] if j > i: sums[i, j] += sums[i, j - 1] s = sorted(sums.values())...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER R...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sums = [] num = len(nums) - 1 for i in range(len(nums)): x = 0 for j in range(i, i + num + 1): x += nums[j] sums.append(x) num -= 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR N...
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: temp = [] for i in range(n): summ = 0 for j in nums[i:]: summ += j temp.append(summ) temp.sort() result = int(sum(temp[left - 1 : right]...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR VAR
Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the n...
class Solution: def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int: sumarr = [nums[0]] * n for i in range(1, n): sumarr[i] = sumarr[i - 1] + nums[i] ansarr = [] for i in range(n): for j in range(i, n): x = sumarr[j] - (s...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR V...
You are given n segments on a number line, numbered from 1 to n. The i-th segments covers all integer points from l_i to r_i and has a value w_i. You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it's possible to travel between two integer points if there exists a...
from sys import stdin, stdout class LazySegmentTree: def __init__(self, data, default=0, func=min): self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self._lazy = [0] * (2 * _size) self.data = [de...
CLASS_DEF FUNC_DEF NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN ...
You are given an array consisting of $n$ integers $a_1, a_2, \dots , a_n$ and an integer $x$. It is guaranteed that for every $i$, $1 \le a_i \le x$. Let's denote a function $f(l, r)$ which erases all values such that $l \le a_i \le r$ from the array $a$ and returns the resulting array. For example, if $a = [4, 1, 1, ...
import sys input = sys.stdin.readline n, x = map(int, input().split()) A = list(map(int, input().split())) MIN_R = [A[-1]] for a in A[:-1][::-1]: MIN_R.append(min(a, MIN_R[-1])) MIN_R = MIN_R[::-1] MAX = x for i in range(n - 1): if A[i] > MIN_R[i + 1]: MAX = min(MAX, A[i]) MAX_L = [A[0]] for a in A[1:]...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUM...
You are given an array consisting of $n$ integers $a_1, a_2, \dots , a_n$ and an integer $x$. It is guaranteed that for every $i$, $1 \le a_i \le x$. Let's denote a function $f(l, r)$ which erases all values such that $l \le a_i \le r$ from the array $a$ and returns the resulting array. For example, if $a = [4, 1, 1, ...
n, x = map(int, input().split()) a = list(map(int, input().split())) fst, last, sm = [], [], [] for i in range(1000005): fst.append(0) last.append(0) sm.append(0) for i in range(n): if fst[a[i]] == 0: fst[a[i]] = i + 1 last[a[i]] = i + 1 for i in range(x + 2): if fst[i] == 0: fst...
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 LIST LIST LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN ...
You are given an array consisting of $n$ integers $a_1, a_2, \dots , a_n$ and an integer $x$. It is guaranteed that for every $i$, $1 \le a_i \le x$. Let's denote a function $f(l, r)$ which erases all values such that $l \le a_i \le r$ from the array $a$ and returns the resulting array. For example, if $a = [4, 1, 1, ...
N, X = map(int, input().split(" ")) class Next: def __init__(self, arr): next_ = [None for _ in arr] for i in range(len(arr) - 2, -1, -1): next_[i] = next_[i + 1] if arr[i + 1] != None: next_[i] = i + 1 self.next_ = next_ def get_next(self, val...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF ASSIGN VAR NONE VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NONE ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_DEF RETURN VAR VAR FUNC_D...
You are given an array consisting of $n$ integers $a_1, a_2, \dots , a_n$ and an integer $x$. It is guaranteed that for every $i$, $1 \le a_i \le x$. Let's denote a function $f(l, r)$ which erases all values such that $l \le a_i \le r$ from the array $a$ and returns the resulting array. For example, if $a = [4, 1, 1, ...
n, x = map(int, input().split()) a = list(map(int, input().split())) mi = [x + 1] * (x + 1) ma = [0] * (x + 1) trie = [0] * (1 << 23) m = 4 trie[0] = x + 1 for i in a: at = 0 mii = x + 1 maa = 0 for j in range(19, -1, -1): if i & 1 << j: if not trie[at + 3]: trie[at +...
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 BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER BI...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: l = len(arr) s = sorted(arr) middle = (l - 1) // 2 median = s[middle] distances = [] for i in s: distances.append([abs(i - median), i]) strong_sort = sorted(distances, ke...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr = sorted(arr) m = (len(arr) - 1) // 2 mv = arr[m] ans = [] i, j = 0, len(arr) - 1 while k and i <= j: rv, lv = abs(arr[j] - mv), abs(arr[i] - mv) if rv > lv: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: n = len(arr) arr_pair = [(i, arr[i]) for i in range(n)] arr_pair.sort(key=lambda x: x[1]) median = arr_pair[(n - 1) // 2][1] max_val = max([abs(x) for x in arr]) arr_pair = [(x[0], abs(x[1] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr.sort() n = len(arr) median = arr[(n - 1) // 2] left, right = 0, n - 1 result = [] while k > 0 and left <= right: if arr[right] - median >= median - arr[left]: ...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL V...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: res = [] arr.sort() j = len(arr) - 1 if j == 0: return arr median = arr[j // 2] i = 0 count = 1 while count <= k: if abs(arr[i] - median) > abs(arr[j]...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUM...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: n = len(arr) if k == n: return arr arr.sort() med = arr[(len(arr) - 1) // 2] sorted_diff = sorted(arr, key=lambda x: abs(x - med)) return sorted_diff[-k:]
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr.sort() m = arr[floor((len(arr) - 1) / 2)] res = [] while len(res) < k: if abs(arr[-1] - m) >= abs(arr[0] - m): res.append(arr[-1]) del arr[-1] els...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR N...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: res = [] valuearr = [] arr.sort() m = arr[int((len(arr) - 1) / 2)] for i in arr: value = [] value.append(i) value.append(abs(i - m)) valuearr.append(v...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr = sorted(arr) l = len(arr) if l % 2 == 0: median = arr[(l - 1) // 2] else: median = arr[l // 2] print(median) s = sorted(arr, key=lambda x: (-abs(x - median), -x)...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR ...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: n = len(arr) if not arr or n == 0: return [] arr.sort() m = arr[(n - 1) // 2] return sorted(arr, reverse=True, key=lambda x: (abs(x - m), x))[:k]
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: sort = sorted(arr) m = sort[int((len(arr) - 1) / 2)] sort.reverse() sorted_by_m = sorted(sort, key=lambda x: abs(x - m), reverse=True) print(m, sorted_by_m) return sorted_by_m[:k]
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: n = len(arr) arr = sorted(arr) m = -1 if n % 2 == 0: m = arr[(n - 1) // 2] else: m = arr[n // 2] ans = [] left = 0 right = n - 1 while k > 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR BIN_OP V...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr.sort() return sorted(arr, key=lambda num: (abs(num - arr[(len(arr) - 1) // 2]), num))[ -k: ]
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], K: int) -> List[int]: arr.sort() length = len(arr) res = arr[(length - 1) // 2] i = 0 j = length - 1 result = [] while K > 0: a = abs(arr[i] - res) b = abs(arr[j] - res) ...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: m = sorted(arr)[(len(arr) - 1) // 2] return [(-x) for _, x in sorted((-abs(x - m), -x) for x in arr)[:k]]
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr.sort() n = len(arr) mid = arr[(n - 1) // 2] h = collections.defaultdict(list) for i in arr: h[abs(i - mid)].append(i) sorted_data = sorted(h.items(), reverse=True) re...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE FUNC_CALL VAR VAR NUM...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: result = [] left = 0 right = len(arr) - 1 arr.sort() m = arr[(len(arr) - 1) // 2] while left <= right: m_left = abs(m - arr[left]) m_right = abs(m - arr[right]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr.sort() med = arr[(len(arr) - 1) // 2] heap = [] for a in arr: strength = abs(a - med) if len(heap) == k: heappushpop(heap, (strength, a)) else: ...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR VAR VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, lis: List[int], k: int) -> List[int]: n = len(lis) lis.sort() med = lis[(n - 1) // 2] ans = [[abs(med - lis[i]), lis[i]] for i in range(n)] ans.sort(reverse=True) fin = [] for i in range(k): fin.append(ans[i]...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VA...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr.sort() mid = (len(arr) - 1) // 2 m = arr[mid] temp = sorted(arr, key=lambda x: abs(x - m)) return temp[-1 * k :]
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR BIN_OP NUMBER VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr = sorted(arr) n = len(arr) if k == n: return arr if n % 2 == 0: median = arr[n // 2 - 1] else: median = arr[n // 2] i = 0 j = n - 1 an...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE NUMBER IF BIN_OP VAR VAR VAR BIN...
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: arr = sorted(arr) m = arr[(len(arr) - 1) // 2] power = [abs(x - m) for x in arr] order = sorted(zip(power, arr), reverse=True) return [order[i][1] for i in range(k)]
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR
Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. Return a list of the strongest k values in the...
class Solution: def getStrongest(self, arr: List[int], k: int) -> List[int]: n = len(arr) d = {} sort = sorted(arr) if n % 2 == 1: m = sort[n // 2] else: m = sort[(n - 1) // 2] for num in arr: val = abs(num - m) if val ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR V...