#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
std::vector<std::pair<std::size_t, std::size_t>>
compute_range_greater_than(const std::vector<int>& v, int threshold)
{
std::vector<std::pair<std::size_t, std::size_t>> res;
for (auto it = v.begin(); it != v.end(); /*Empty*/)
{
auto beg = std::find_if(it, v.end(), [=](int i) { return !(i < threshold); });
if (beg == v.end()) {
return res;
}
it = std::find_if(beg, v.end(), [=](int i) { return i < threshold; });
// using 1-index
res.push_back({1 + std::distance(v.begin(), beg), std::distance(v.begin(), it)});
}
return res;
}
int main()
{
auto ranges = compute_range_greater_than({600, 250, 600, 600, 600}, 500);
for (auto r : ranges) {
std::cout << r.first << "-" << r.second << std::endl;
}
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnN0ZDo6dmVjdG9yPHN0ZDo6cGFpcjxzdGQ6OnNpemVfdCwgc3RkOjpzaXplX3Q+Pgpjb21wdXRlX3JhbmdlX2dyZWF0ZXJfdGhhbihjb25zdCBzdGQ6OnZlY3RvcjxpbnQ+JiB2LCBpbnQgdGhyZXNob2xkKQp7CiAgICBzdGQ6OnZlY3RvcjxzdGQ6OnBhaXI8c3RkOjpzaXplX3QsIHN0ZDo6c2l6ZV90Pj4gcmVzOwoKICAgIGZvciAoYXV0byBpdCA9IHYuYmVnaW4oKTsgaXQgIT0gdi5lbmQoKTsgLypFbXB0eSovKQogICAgewogICAgICAgIGF1dG8gYmVnID0gc3RkOjpmaW5kX2lmKGl0LCB2LmVuZCgpLCBbPV0oaW50IGkpIHsgcmV0dXJuICEoaSA8IHRocmVzaG9sZCk7IH0pOwogICAgICAgIGlmIChiZWcgPT0gdi5lbmQoKSkgewogICAgICAgICAgICByZXR1cm4gcmVzOwogICAgICAgIH0KICAgICAgICBpdCA9IHN0ZDo6ZmluZF9pZihiZWcsIHYuZW5kKCksIFs9XShpbnQgaSkg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