SHARE
TWEET

Untitled

a guest Jan 21st, 2018 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. #pragma GCC optimize ("O3")
  6.  
  7. int main()
  8. {
  9.     std::cout.sync_with_stdio(false);
  10.     std::cin.sync_with_stdio(false);
  11.     std::cin.tie(nullptr);
  12.  
  13.     int D, N, income;
  14.     std::vector<int> numbers;
  15.  
  16.     std::cin >> D >> N;
  17.  
  18.     while (N-- > 0)
  19.     {
  20.         std::cin >> income;
  21.         numbers.push_back(income);
  22.     }
  23.  
  24.     std::sort(numbers.begin(), numbers.end());
  25.  
  26.     int low_bound = numbers.front() + D;
  27.     int high_bound = numbers.back() - D;
  28.     double sum = 0.0;
  29.     int items_count = 0;
  30.     for (auto item : numbers)
  31.     {
  32.         if (item <= low_bound)
  33.         {
  34.             continue;
  35.         }
  36.  
  37.         if (item >= high_bound)
  38.         {
  39.             break;
  40.         }
  41.  
  42.         sum += item;
  43.         items_count++;
  44.     }
  45.  
  46.     std::cout << sum / items_count << std::endl;
  47.  
  48.     return 0;
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top