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));
var maxVol = list.MaxBy(t => t.Volume);
var minPr = list.Min(t => t.Price);
var maxPr = list.Max(t => t.Price);
.Where(t => t.Price > maxVol.Price)
.Concat(Enumerable.Repeat<(double Price, double Volume)>((maxPr,0.0), list.Count))
.Where(t => t.Price < maxVol.Price)
.Concat(Enumerable.Repeat<(double Price, double Volume)>((minPr, 0.0), list.Count))
.SelectMany(tz => new []{ tz.Item1, tz.Item2 })
.Select(c => new{ MinPrice = c.Min(t => t.Price), MaxPrice = c.Max(t => t.Price), RollingSum = sum, RollingSumNext = (sum += c.First().Volume + c.Last().Volume) } )
.Where(at => at.RollingSum < 240000)
minPr = pairs.Min(at => at.MinPrice);
maxPr = pairs.Max(at => at.MaxPrice);
Console.WriteLine(minPr);
Console.WriteLine(maxPr);