using System.Collections.Generic;
public static void Main()
var list = new List<(double Price, double Volume)>();
list.Add((9638.0, 3217.0));
list.Add((9637.0, 3215.0));
list.Add((9636.0, 3215.0));
list.Add((9635.0, 3215.0));
list.Add((9634.0, 3215.0));
list.Add((9633.0, 3215.0));
list.Add((9632.0, 3215.0));
list.Add((9631.0, 3215.0));
list.Add((9630.0, 3215.0));
list.Add((9629.0, 3215.0));
list.Add((9628.0, 3215.0));
list.Add((9627.0, 3215.0));
list.Add((9626.0, 3215.0));
list.Add((9625.0, 3215.0));
list.Add((9624.0, 3215.0));
list.Add((9623.0, 4311.0));
list.Add((9622.0, 5071.0));
list.Add((9621.0, 6056.0));
list.Add((9620.0, 9087.0));
list.Add((9619.0, 10819.0));
list.Add((9618.0, 14921.0));
list.Add((9617.0, 16496.0));
list.Add((9616.0, 17601.0));
list.Add((9615.0, 19626.0));
list.Add((9614.0, 21800.0));
list.Add((9613.0, 21973.0));
list.Add((9612.0, 22168.0));
list.Add((9611.0, 18791.0));
list.Add((9610.0, 15700.0));
list.Add((9609.0, 16900.0));
list.Add((9608.0, 13971.0));
list.Add((9607.0, 12367.0));
list.Add((9606.0, 8706.0));
list.Add((9605.0, 7134.0));
list.Add((9604.0, 6107.0));
list.Add((9603.0, 5341.0));
list.Add((9602.0, 3827.0));
var maxVol = list.MaxBy(t => t.Volume);
.Where(t => t.Price > maxVol.Price)
list.Where(t => t.Price < maxVol.Price)
.SelectMany(tz => new []{ tz.Item1, tz.Item2 })
.Select(c => new{ MinPrice = c.Min(t => t.Price), MaxPrice = c.Max(t => t.Price), RollingSum = (sum += c.First().Volume + c.Last().Volume) } )
.Where(at => at.RollingSum < 240000)
var minPr = pairs.Min(at => at.MinPrice);
var maxPr = pairs.Max(at => at.MaxPrice);
Console.WriteLine(minPr);
Console.WriteLine(maxPr);