Advertisement
Semior001

b task

Dec 4th, 2016
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cstring>
  6. #include <vector>
  7. #include <cstdio>
  8. #include <map>
  9. #include <utility>
  10. #include <queue>
  11. #include <stack>
  12. #include <deque>
  13. #include <iomanip>
  14. #include <fstream>
  15.  
  16. #define INF (1<<30)
  17. #define F first
  18. #define S second
  19. #define pb push_back
  20. #define mp make_pair
  21. #define FOR(a,b) for(int i = a; i < b; i++)
  22. #define FORR(a,b) for(int i = a; i >= b; i--)
  23. #define FORJ(a,b) for(int j = a; j < b; j++)
  24. #define FORRJ(a,b) for(int j = a; j >= b; j--)
  25. #define FORN(n) for(int i = 0; i < n; i++)
  26. #define FORJN(n) for(int j = 0; j < n; j++)
  27. #define endl '\n'
  28.  
  29. #define TASKNAME "che"
  30.  
  31. typedef long long ll;
  32. typedef long double ld;
  33.  
  34. using namespace std;
  35.  
  36. const int MAXN = 3e5;
  37.  
  38. int n,r,j;
  39. int pred = 1;
  40. ll ans = 0;
  41. vector<int> a(MAXN+10);
  42.  
  43. int main(){
  44.     // freopen(TASKNAME".in", "r", stdin);
  45.     // freopen(TASKNAME".out", "w", stdout);
  46.     ios_base::sync_with_stdio(false);
  47.     cin.tie(NULL);
  48.     cin >> n >> r;
  49.     FORN(n){
  50.         cin >> a[i];
  51.     }
  52.     for (int i=0; i < n && a[i]+r<a[n-1]; i++){
  53.         j=pred;
  54.         while(a[i] + r >= a[j] && j < n)
  55.             j++;
  56.         pred=j;
  57.         ans += n - pred;
  58.     }
  59.     cout << ans << endl;
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement