int N = segments.size(); vector> sortedSegments = segments; sort(sortedSegments.begin(), sortedSegments.end(), [](const vector &a, const vector &b) { return a[1] < b[1]; }); priority_queue, vector>, greater>> minHeap; int min_cost = numeric_limits::max(); for (const auto &segment : sortedSegments) { int L = segment[0]; int R = segment[1]; int cost = segment[2]; while (!minHeap.empty() && minHeap.top().first >= L) { minHeap.pop(); } if (!minHeap.empty()) { int pairing_cost = minHeap.top().second * cost; min_cost = min(min_cost, pairing_cost); } minHeap.push({R, cost}); } return (min_cost != numeric_limits::max()) ? min_cost : -1; }