Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <string>
- #include <cstring>
- #include <vector>
- #include <cstdio>
- #include <map>
- #include <utility>
- #include <queue>
- #include <stack>
- #include <deque>
- #include <iomanip>
- #include <fstream>
- #define INF (1<<30)
- #define F first
- #define S second
- #define pb push_back
- #define mp make_pair
- #define FOR(a,b) for(int i = a; i < b; i++)
- #define FORR(a,b) for(int i = a; i >= b; i--)
- #define FORJ(a,b) for(int j = a; j < b; j++)
- #define FORRJ(a,b) for(int j = a; j >= b; j--)
- #define FORN(n) for(int i = 0; i < n; i++)
- #define FORJN(n) for(int j = 0; j < n; j++)
- #define endl '\n'
- #define TASKNAME "che"
- typedef long long ll;
- typedef long double ld;
- using namespace std;
- const int MAXN = 3e5;
- int n,r,j;
- int pred = 1;
- ll ans = 0;
- vector<int> a(MAXN+10);
- int main(){
- // freopen(TASKNAME".in", "r", stdin);
- // freopen(TASKNAME".out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cin >> n >> r;
- FORN(n){
- cin >> a[i];
- }
- for (int i=0; i < n && a[i]+r<a[n-1]; i++){
- j=pred;
- while(a[i] + r >= a[j] && j < n)
- j++;
- pred=j;
- ans += n - pred;
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement