[Mảng 1 Chiều Cơ Bản]. Bài 56. Cặp số có hiệu bằng k

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Problem source:
28Tech
Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho mảng A[] gồm N phần tử và số nguyên k, bạn hãy đếm xem trong mảng có bao nhiêu cặp số có hiệu bằng k


Đầu vào

Dòng 1 là Nk

Dòng 2 là N số viết cách nhau 1 dấu cách


Giới hạn

1≤N≤10^3

0≤A[i], k≤10^6


Đầu ra

In ra số cặp thỏa mãn


Ví dụ :

Input 01
6 2
1 3 3 2 4 4
Output 01
4

Comments

Please read the guidelines before commenting.



  • 0
    Longbaka  commented on Jan. 7, 2026, 2:45 a.m.

    test toàn 1 với 0 hay sao ấy =))))))))))


  • 0
    bennie15025_meow  commented on Jan. 2, 2026, 2:14 a.m.

    HMS: https://onecompiler.com/cpp/449ch3rqy


  • 0
    kietne  commented on Dec. 29, 2025, 1:58 p.m.

    include <bits/stdc++.h>

    using namespace std; using ll = long long; using ull = unsigned long long;

    int main() { ios::syncwithstdio(false); cin.tie(nullptr); int n,k; cin >> n >> k; int a[n]; int dem=0; for(auto &i : a) cin >> i; for(int i = 0; i < n; i++){ for(int j = i+1; j<n; j++){ if(abs(a[i]-a[j])==k) dem++; } } cout << dem; return 0; }