i was doing some problem in some competitive coding site, it basically ask you to count how many element is greater than min and lower or equal to the max
for example, i have an array {3,6,8,10,20} and the min is 2 and the max is 15 the number of element is 4 (from 3 to 10) if i changed the min to 10 and the max to 20 the number of element is 1 (20) because 20 is equal to the max
this is my code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<int> bebek;
std::vector<int>::iterator low1, up1;
int N,Q, input, input2, ct;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> input;
bebek.push_back(input);
}
cin >> Q;
for (int i = 0; i < Q; i++)
{
cin >> input >> input2;
low1 = lower_bound(bebek.begin(), bebek.end(), input+1);
up1 = upper_bound(bebek.begin(), bebek.end(), input2-1);
cout << distance(low1, up1) << endl;
}
return 0;
}
input:
5 (number of the element in array)
3 6 8 10 20 (the elements)
2 (the number of min and max)
2 15 (min and max)
10 20 (min max 2nd)
expected output:
4
1
current output:
4
0
what can i do to improve my algorithm