PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000121. Đếm cặp có tổng trong khoảng (Count the Number of Fair Pairs)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm cặp có tổng trong khoảng (Count the Number of Fair Pairs)
Count the Number of Fair Pairs
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array and bounds , a pair of distinct positions is fair if and . Equal values at different positions still correspond to different pairs. Count all fair pairs.
Input
The first line contains . The second line contains integers .
Output
Print the number of fair position pairs.
Subtasks
- Subtask 1 (20 points): ; , .
- Subtask 2 (30 points): ; , .
- Subtask 3 (50 points): ; , .
Examples
Input
6 3 6
0 1 7 4 4 5
Output
6
Explanation
The six fair one-based pairs are , , , , , and . Their sums are , all in . The two occurrences of are at distinct positions, so count separately. Print 6.