public static void Main()
int[] weight = { 345,345,175,175,175,175,470,470,470,470,345,345,175,175,200,200,200,200,300,300,400,400,350 };
Console.Write("Total: " + weight.Sum() +
+ GFG.bestFit(weight, n, c) + " pieces max");
public static class GFG {
public static int bestFit(int[] weight, int n, int c)
int[] bin_rem = new int[n];
for (int i = 0; i < n; i++) {
for (j = 0; j < res; j++) {
if (bin_rem[j] >= weight[i]
&& bin_rem[j] - weight[i] < min) {
min = bin_rem[j] - weight[i];
bin_rem[res] = c - weight[i];
bin_rem[bi] -= weight[i];