PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000200. Phân biệt tiền tố đơn điệu (Testing Monotone Prefix Assumptions)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phân biệt tiền tố đơn điệu (Testing Monotone Prefix Assumptions)

Testing Monotone Prefix Assumptions

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers a1,…,ana_1,\ldots,a_n (possibly negative) and a positive integer KK, find the shortest nonempty consecutive interval with sum at least KK, or -1 if none exists. A student uses the following algorithm:

l = 1, sum = 0, best = n + 1
for r = 1 .. n:
    sum = sum + a[r]
    while l <= r and sum >= K:
        best = min(best, r-l+1)
        sum = sum - a[l]
        l = l + 1
if best == n + 1: best = -1

This algorithm can fail on negative elements. Print the correct answer and the best value returned by the exact algorithm above, even if they are equal. Different values identify a counterexample.

Input

The first line contains n,Kn,K. The second line contains exactly nn integers aia_i.

Output

Print two space-separated integers on one line: the correct answer and the result of the prescribed algorithm.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; −109≤ai≤109-10^9\le a_i\le10^9; 1≤K≤2⋅10141\le K\le2\cdot10^{14}.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; −109≤ai≤109-10^9\le a_i\le10^9; 1≤K≤2⋅10141\le K\le2\cdot10^{14}; ai≥0a_i\ge0.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; −109≤ai≤109-10^9\le a_i\le10^9; 1≤K≤2⋅10141\le K\le2\cdot10^{14}.

Example 1

Input

2 4
-2 5

Output

1 -1

Explanation

Interval [2,2] sums to 5; the prescribed algorithm sees sums -2 and 3 and never shrinks its window.

Example 2

Input

3 4
2 1 3

Output

2 2

Explanation

Interval [2,3] sums to 4; the prescribed algorithm also finds length 2.