using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
List<int> arr = new List<int>(){100,50,20,10};
List<int> result = new List<int>();
int entry = 30;
//int checkVal = entry - arr.Max();
for(int i= 0; i < arr.Count(); i++){
int x = arr[i];
int checkVal = entry - x ;
if(checkVal >= 0){
int max = arr.Max(); // 20
int temp = entry - max; //10
if(temp <= max){
result.Add(max);
entry = temp;
arr.Remove(max);
i--;
}
}else{
arr.Remove(x);
foreach(int x in result){
Console.WriteLine(x);