We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 45ad432 + ac30214 commit 7e6041dCopy full SHA for 7e6041d
1 file changed
Problems/Mathematics/Day-02/sol/Kushagra Raghuvanshi/Solution2.cpp
@@ -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