We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bad08d7 commit 6733aa0Copy full SHA for 6733aa0
1 file changed
Problems/Mathematics/Day-02/sol/Ayush Mishra/Solution1.cpp
@@ -0,0 +1,44 @@
1
+// Submission Link
2
+// https://codeforces.com/contest/1771/submission/355396669
3
+// Time complexity = O(n) + O(nlogn)
4
+// Space Comlexity = O(n)
5
+
6
7
8
9
10
+#include<bits/stdc++.h>
11
+using namespace std;
12
+int main(){
13
+ int t;
14
+ cin>>t;
15
+ while(t--){
16
+ long long int n;
17
+ cin>>n;
18
+ vector<long long int>v(n);
19
+ for(int i=0; i<n; i++){
20
+ cin>>v[i];
21
+ }
22
+ sort(v.begin(),v.end());
23
+ long long int mini =0;
24
+ long long int maxi= 0;
25
+ int i=0;
26
+ int j = n-1;
27
+ if(v[0]!=v[n-1]){
28
+ while(v[i]==v[0] && i<n){
29
+ mini++;
30
+ i++;
31
32
+ while(v[j]==v[n-1] && j>=0){
33
+ maxi++;
34
+ j--;
35
36
+ cout<<2*maxi*mini<<"\n";
37
38
+ else{
39
+ cout<<(n*(n-1))<<"\n";
40
41
42
43
+ return 0;
44
+}
0 commit comments