Skip to content

Instantly share code, notes, and snippets.

@MohamedTaha98
Created June 17, 2017 20:50
Show Gist options
  • Save MohamedTaha98/675c1a3f95eb8a2e1e9cb37eaa7c0d94 to your computer and use it in GitHub Desktop.
Save MohamedTaha98/675c1a3f95eb8a2e1e9cb37eaa7c0d94 to your computer and use it in GitHub Desktop.
Problem Solving
#include <iostream>
using namespace std;
int main () {
long long n;
cin >> n;
long ar[n];
for (int i = 0; i < n; i++)
cin >> ar[i];
long min = ar[0];
long max = ar[0];
for (int i = 0; i < n; i++) {
if (ar[i] > max)
max = ar[i];
else if (ar[i] < min)
min = ar[i];
}
long beauty = max - min;
long long ways, cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
if (ar[i] == max)
cnt1++;
else if (ar[i] == min)
cnt2++;
}
if (min == max)
ways = n * (n - 1) / 2;
else
ways = cnt1 * cnt2;
cout << beauty << " " << ways;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment