ĐẾM CẶP PHẦN TỬ

View as PDF

Submit solution

Points: 0.10 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: cappt.inp
Output: cappt.out

Author:
Problem type
Allowed languages
C++, Pascal, Python

Cho dãy số tự nhiên gồm ~N~ phần tử ~a_1, a_2, …, a_N~ và số tự nhiên ~K~.

Yêu cầu:

Đếm số cặp chỉ số ~(i, j)~ mà ~i < j~ và ~a_i + a_j =K~ trong dãy.

Dữ liệu:

Vào từ file CAPPT.INP:

• Dòng đầu tiên chứa hai số nguyên ~N, K (2 \leq N \leq 3 \times 10^6, 1 \leq K \leq 10^6)~

• Dòng thứ hai là dãy số ~a_1, a_2, …, a_N~ có giá trị không vượt quá ~10^6~.

Kết quả:

Ghi vào tệp CAPPT.OUT chứa số cặp ~a_i, a_j~ có tổng bằng ~K~

Ví dụ 1:

CAPPT.INP

5 1
1 5 4 1 2

CAPPT.OUT

0

Ví dụ 2:

CAPPT.INP

4 6
3 2 3 3

CAPPT.OUT

3

Ràng buộc:

• Subtask1: ~80\%~ test ~1 \leq N \leq 10^3~

• Subtask2: ~20\%~ test ~10^3 \leq N \leq 3\times 10^6~.


Comments

Please read the guidelines before commenting.


There are no comments at the moment.