Harry loves numbers in the range [m1, m2] (m1 and m2 included). carry decides to gift harry an array of numbers for his birthday. harry wants to find the number of pairs of indices [l, r] for which the sum of all the elements in the range [l, r] lies between m1 and m2.
#include <iostream>
using namespace std;
int n, m1, m2, g[100], a = 0;
int main()
{
cin >> n >> m1 >> m2;
for (int i = 0; i < n; i++) cin >> g[i];
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (i != j && g[i]+g[j]<=m2 && g[i]+g[j]>=m1) a++;
}
}
cout << a;
return 0;
}
Comments
Leave a comment