Skip to content

Commit 7e6041d

Browse files
authored
Merge pull request #321 from Taskmaster-afk/main
Solution for Q1 Day2
2 parents 45ad432 + ac30214 commit 7e6041d

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

  • Problems/Mathematics/Day-02/sol/Kushagra Raghuvanshi
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//https://codeforces.com/problemset/submission/1771/355389933
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
int main() {
7+
int t;
8+
cin >> t;
9+
10+
while (t--) {
11+
int n;
12+
cin >> n;
13+
14+
long long a[n];
15+
for (int i = 0; i < n; i++)
16+
cin >> a[i];
17+
18+
long long mn = a[0], mx = a[0];
19+
for (int i = 1; i < n; i++) {
20+
mn = min(mn, a[i]);
21+
mx = max(mx, a[i]);
22+
}
23+
24+
long long cmin = 0, cmax = 0;
25+
for (int i = 0; i < n; i++) {
26+
if (a[i] == mn) cmin++;
27+
if (a[i] == mx) cmax++;
28+
}
29+
30+
if (mn == mx)
31+
cout << n * (n - 1) << "\n";
32+
else
33+
cout << 2 * cmin * cmax << "\n";
34+
}
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)