Submission #435138

#TimeUsernameProblemLanguageResultExecution timeMemory
435138sumit_kk10Pairs (IOI07_pairs)C++14
30 / 100
26 ms1976 KiB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

void solve(){
    long long b, n, d, m;
    cin >> b >> n >> d >> m;
    long long a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        int low = i + 1, ok = -1, high = n - 1;
        while(low <= high){
            int mid = (low + high) / 2;
            if(a[mid] - a[i] <= d){
                ok = mid;
                low = mid + 1;
            }
            else
                high = mid - 1;
        }
        if(ok != -1)
            ans += (ok - i);
    }
    cout << ans << '\n';
}

int main(){
    fast;
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...