int findMinPairingCost(const vector& segments) { int minCost = INT_MAX; int n = segments.size(); if (n < 2) return -1; vector sortedSegments = segments; sort(sortedSegments.begin(), sortedSegments.end(), [](const Segment& a, const Segment& b) { return a.R < b.R || (a.R == b.R && a.L < b.L); }); int minSingleCost = INT_MAX; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (sortedSegments[j].R < sortedSegments[i].L) { int pairCost = sortedSegments[i].cost * sortedSegments[j].cost; minCost = min(minCost, pairCost); } } } return minCost == INT_MAX ? -1 : minCost; }