Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int const maxen = 10000;
- int main()
- {
- int n; cin >> n;
- int d; cin >> d;
- vector <int> a(n);
- bool used[maxen];
- for(int i= -n-7; i < n+7; i++){
- used[i] = false;
- }
- for(int i=0; i < n; i++){
- cin >> a[i];
- used[a[i]] = true;
- }
- int rew[maxen];
- int q = 0;
- for(int i = 0; i < n; i++){
- rew[q] = a[i]-d;
- q++;
- rew[q] = a[i];
- q++;
- rew[q] = a[i]+d;
- q++;
- }
- int ans = 0;
- sort(rew,rew*3+1);
- for(int i = 0; i < n*3; i++){
- cout << rew[i]<< endl;
- }
- return 0;
- for(int i = 0; i < n*3-1; i++){
- if(used[rew[i]] == true){
- if(rew[i] - d == rew[i-1]){
- ans++;
- }
- if(rew[i] + d == rew[i+1]){
- ans++;
- cout << ans << endl << i;
- return 0;
- }
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement