Submission #435138

# Submission time Handle Problem Language Result Execution time Memory
435138 2021-06-23T03:52:16 Z sumit_kk10 Pairs (IOI07_pairs) C++14
30 / 100
26 ms 1976 KB
#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 time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1468 KB Output is correct
2 Correct 18 ms 1476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1960 KB Output is correct
2 Correct 23 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1860 KB Output is correct
2 Correct 25 ms 1844 KB Output is correct
3 Correct 25 ms 1976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 1472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 1844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1484 KB Output isn't correct
2 Halted 0 ms 0 KB -