eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Segment Sum

Segment Sum

A segment of a sequence \textbf{a_1}, \textbf{a_2}, …, \textbf{a_N} is a sequence \textbf{a_i}, \textbf{a_\{i+1\}}, …, \textbf{a_j} for some \textbf{1} ≤ \textbf{i} ≤ \textbf{j} ≤ \textbf{N}. Given an integer sequence consider a set of all its segments, ordered by the sum of elements. Your task is to find the sum of elements of \textbf{K}-th segment in this order (\textbf{0}-based). In this problem two segments are considered different, if one of their ends does not coincide. So actually it can be a multiset, for example for sequence \textbf{2}, \textbf{2} all its different segments are \{\textbf{2}\}, \{\textbf{2}\}, \{\textbf{2},\textbf{2}\}. Therefore any sequence of length \textbf{N} will have exactly \textbf{N(N+1)/2} segments. For given example, their sums will be \textbf{2}, \textbf{2}, \textbf{4} in order. \InputFile First line of input contains two integer numbers \textbf{N} and \textbf{K} -- length of the sequence and \textbf{0}-based number of interesting segment (\textbf{1} ≤ \textbf{N} ≤ \textbf{10^5}, \textbf{0} ≤ \textbf{K} < \textbf{N(N+1)/2}). Second line contains \textbf{N} integers \textbf{a_1}, \textbf{a_2}, …, \textbf{a_N} -- the elements of the sequence (\textbf{-10^9} ≤ \textbf{a_i} ≤ \textbf{10^9}). \OutputFile Sum of elements of \textbf{K}-th segment in this order (\textbf{0}-based).
Ліміт часу 2 секунди
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
3 0
1 4 -3
Вихідні дані #1
-3
Джерело International Collegiate Programming Contest, Ukraine, Quarter-Final,May 19, 2011