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

#PS0000198. Tổng đoạn nhỏ nhất có độ dài thuộc khoảng (Minimum Subarray Sum With Length Bounds)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng đoạn nhỏ nhất có độ dài thuộc khoảng (Minimum Subarray Sum With Length Bounds)

Minimum Subarray Sum With Length Bounds

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integers and two length bounds L,RL,R, find the minimum sum of any consecutive interval [l,r][l,r] satisfying 1≤l≤r≤n1\le l\le r\le n and L≤r−l+1≤RL\le r-l+1\le R. Empty intervals are forbidden. A valid interval always exists since 1≤L≤R≤n1\le L\le R\le n.

Input

The first line contains n,L,Rn,L,R. The second contains exactly nn integers aia_i.

Output

Print the minimum sum.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; −109≤ai≤109-10^9\le a_i\le10^9; 1≤L≤R≤n1\le L\le R\le n.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; −109≤ai≤109-10^9\le a_i\le10^9; 1≤L≤R≤n1\le L\le R\le n; L=RL=R.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; −109≤ai≤109-10^9\le a_i\le10^9; 1≤L≤R≤n1\le L\le R\le n.

Example 1

Input

5 2 3
3 -5 2 -4 6

Output

-7

Explanation

Interval [2,4] sums to -7. Length-two sums are -2,-3,-2,2; length-three sums are 0,-7,4.

Example 2

Input

3 1 2
4 1 3

Output

1

Explanation

Interval [2,2] sums to 1, the minimum among eligible intervals.