using System; using System.Collections.Generic; var stock = new[] { new Item("A-01", "Notebook", 220), new Item("A-02", "Canvas bag", 280), new Item("A-03", "Pencil set", 100), new Item("B-01", "Wooden tray", 510), }; const int weightLimitGrams = 500; IReadOnlyList parcel = FillBox(stock, weightLimitGrams); Console.WriteLine($"Box capacity: {weightLimitGrams} g"); Console.WriteLine("Consider items in order. Pack each item that fits, including an exact fit."); Console.WriteLine(); PrintBox(parcel, weightLimitGrams); static IReadOnlyList FillBox(IReadOnlyList stock, int capacity) { var packed = new List(); int used = 0; foreach (Item item in stock) { if (used + item.WeightGrams < capacity) { packed.Add(item); used += item.WeightGrams; } } return packed; } static void PrintBox(IReadOnlyList packed, int capacity) { int totalWeight = 0; Console.WriteLine("Packed items"); foreach (Item item in packed) { Console.WriteLine($"{item.Sku}: {item.Name} ({item.WeightGrams} g)"); totalWeight += item.WeightGrams; } Console.WriteLine($"Weight used: {totalWeight} g"); Console.WriteLine($"Weight available: {capacity - totalWeight} g"); } record Item(string Sku, string Name, int WeightGrams); // Есть ли баги в этом коде?