Here is the link to the problem: https://codeforces.com/contest/768/problem/A
My approach is that as we need to find the number of elements that has at least 1 strictly greater than itself and also has least 1 strictly smaller than it, therefore in the sorted list the 1st and the last element can’t be added to the answer. So a simple way to do this is use maps in C++. So I used the normal maps in C++ which maintains the order of the elements and I implemented the process that I mentioned before of ignoring all the elements that are the smallest and the largest in the list and added the rest of the elements to my answer. But I am getting WA in test case 3. Can anyone please tell me if there was any mistake in my approach and also in my implementation. It will be very helpful. Thanks in advance.
Here is my code:
#include <bits/stdc++.h>
using namespace std;
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void solve() {
int n; cin >> n; int count = 0;
map <int, int> m;
int temp;
while (n--) {
cin >> temp;
m[temp]++;
}
auto it = m.begin();
it = next(it, 1);//Exclude the first item in the map.
while (it != m.end()) {
count += it->second;
++it;
}
cout << count - m[m.size()-1]; // Exclude the last item in the map
}
int main(){
FIO;
int tc = 1;
//cin >> tc;
while (tc--) {
solve();
cout << '\n';
}
}