Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. int main(){
  10.     ios_base::sync_with_stdio(false);
  11.     int n;
  12.     cin >> n;
  13.     vector<int> a(n);
  14.     for(int i = 0; i < n; ++i){ cin >> a[i]; }
  15.     const int min_value = *min_element(a.begin(), a.end());
  16.     const int max_value = *max_element(a.begin(), a.end());
  17.     const int min_count = count(a.begin(), a.end(), min_value);
  18.     const int max_count = count(a.begin(), a.end(), max_value);
  19.     ll answer = 0;
  20.     if(min_value == max_value){
  21.         answer = static_cast<ll>(min_count) * (min_count - 1) / 2;
  22.     }else{
  23.         answer = static_cast<ll>(min_count) * max_count;
  24.     }
  25.     cout << max_value - min_value << " " << answer << endl;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement