#include <iostream>
#include <vector>
#include <map>

struct Range {
    std::size_t start;
    std::size_t last;
};

int duration(const Range& range)
{
    return range.last - range.start;    
}

bool operator < (const Range& lhs, const Range& rhs)
{
    return duration(lhs) < duration(rhs);
}

std::map<int, Range>
compute_profits(const std::vector<int>& shares){
    std::map<int, Range> res;
    for (std::size_t i = 0; i != shares.size(); ++i) {
        for (std::size_t j = i + 1; j != shares.size(); ++j) {
            const auto benefit = shares[j] - shares[i];
            const Range range{i, j};
            auto p = res.emplace(benefit, range);
            
            if (!p.second) {
                // Already exist, use the better one
                auto it = p.first;
                it->second = std::min(it->second, range);
            }
        }
    }
    return res;
}

void show_result(const std::vector<int>& shares,
			     const std::vector<int>& benefits)
{
    auto profits = compute_profits(shares);
   
    for (const auto b : benefits) {
        auto it = profits.find(b);
        
        if (it == profits.end()) {
            std::cout << -1 << std::endl;
        } else {
            const auto& range = it->second;
            std::cout << 1 + range.start << " " << 1 + range.last << std::endl;
        }
    }
}

int main()
{
	show_result({ 1, 2, 3, 5}, {3, 8});
	std::cout << "--\n";
	show_result({ 1, 2, 3, 5}, {2});

}