#TP0000047. Đếm cặp có tổng thuộc đoạn (Number of Pairs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm cặp có tổng thuộc đoạn (Number of Pairs)
Number of Pairs
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers and two integers with . Array positions are numbered from through .
A pair is valid when and the sum of the corresponding values lies in the inclusive interval :
Count all valid pairs of positions. Two pairs are distinct if at least one index differs. Equal values at different positions are counted separately.
Input
- The first line contains three integers : the length of the array and the lower and upper sum bounds.
- The second line contains exactly positive integers in order.
Output
Print one integer: the number of index pairs satisfying and .
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
3 4 7
5 1 2
Output
2
Explanation
The array is , and the inclusive sum interval is . The three index pairs are: with sum (valid); with sum (valid because the upper bound is inclusive); and with sum (invalid). Exactly pairs qualify, so the output is 2.