Go: package main

import (
	"bufio"
		"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
var f = make([]string, 10)
var s, w = make([]int, 10), make([]int, 10)
var n int
func main() {
	for scanner.Scan() {
		n, _ = strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			tmpf :=buf[0]
			tmpw, _ := strconv.Atoi(buf[1])
			tmps, _ := strconv.Atoi(buf[2])
			f[i] = tmpf
			s[i] = tmps
			w[i] = tmpw
		}
		sort()
		for i := 0; i < n; i++ {
			for j := 0; j < n-1; j++ {
				if w[j]<w[j+1] {
					swap(j)
					a := get_weight(j+1)
					if a>s[j] {
						swap(j)
					}
				}
			}
		}
		for i := 0; i < n; i++ {
			fmt.Println(f[i])
		}
	}
}

func sort() {
	for i := n-1; i > 0; i-- {
		for j := 0; j < i; j++ {
			if s[j]<s[j+1] {
				swap(j)
			} else if s[j]==s[j+1]&&w[j]<w[j+1] {
				swap(j)
			}
		}
	}
}

func swap(x int) {
	w[x], w[x+1] = w[x+1], w[x]
	s[x], s[x+1] = s[x+1], s[x]
	f[x], f[x+1] = f[x+1], f[x]
}

func get_weight(x int) int {
	ret := 0
	for i := x; i < n; i++ {
		ret += w[i]
	}
	return ret
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	vector<pair<string,pii> > data;
	vector<pair<string,pii> > ans;
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	while(cin>>n,n){
		data.clear();
		ans.clear();
		string str;
		int w,s;
		int tmp2 =0;
		for(int i =0;i <n;i++){
			cin>>str;
			scanf("%d %d",&w,&s);
			data.push_back(mp(str,pii(w,s)));
			tmp2 +=data[i].second.first;
		}
		sort(data.begin(),data.end());
		double G =INF;
		do{
			//cout <<"iei"<<endl;
			int sumw =0;
			int tmp1 =0;
			for(int i =n-1;i >=0;i--){
				tmp1 +=(i+1)*data[i].second.first;
			}
			double Gtmp =(double)((double)tmp1/(double)tmp2);
			if(Gtmp>G)continue;
			bool ok =true;
			for(int i =n-1;i >=0;i--){
				if(sumw>data[i].second.second){
					ok =false;
					break;
				}else{
					sumw +=data[i].second.first;
				}
			}
			//cout <<Gtmp<<endl;
			if(ok&&Gtmp <G){
				G =Gtmp;
				ans=data;
				//cout <<"ge"<<endl;
			}
		}while(next_permutation(data.begin(), data.end()));

		for(int i =0;i <n;i++){
			cout <<ans[i].first<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  int n;
  while(cin>>n,n) {
    string f[n];
    int w[n],s[n];
    int x[n];
    REP(i,n) {
      cin >> f[i] >> w[i] >> s[i];
      x[i] = i;
    }
    int ans[n];
    double ansg = INF;
    do {
      int sum = 0;
      int ct;
      for (ct=n-2; ct>=0; --ct) {
        sum += w[x[ct+1]];
        if (s[x[ct]] < sum)
          break;
      }
      if (ct >= 0) continue;
      
      // REP(i,4) {
      //   cout << x[i] << " ";
      // }
      // cout << endl;
      double g = 0, hoge = 0;
      REP(i,n) {
        g += w[x[i]] * (i+1);
        hoge += w[x[i]];
      }
      g /= hoge;
      // cout << g << endl;
      if (ansg > g) {
        ansg = g;
        memcpy(ans,x,sizeof(x));
      }
    } while(next_permutation(x, x+n));
    REP(i,n)
      //     cout << ans[i] << " ";
     cout << f[ans[i]] << endl;
  }
}

C++: # define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef pair<double, vi> P;
struct food
{
	string name;
	int w;
	int s;
};
int n;
vector<food> a;

P calc(int bit, int s, double g, double d)
{
	if (s < 0)return P(-1, {});
	int _n = __builtin_popcount(bit);
	if (_n == n)
		return P(g / d, {});

	P ans = P(9999999999.0, {});
	FOR(i, n)
	{
		if (bit & 1 << i)continue;
		int nbit = bit | 1 << i;
		int ns = min(s - a[i].w, a[i].s);
		double ng = g + (_n + 1)*a[i].w;
		double nd = d + a[i].w;
		P x = calc(nbit, ns, ng, nd);
		if (x.first < 0)continue;
		if (ans.first > x.first)
		{
			ans = x;
			ans.second.insert(ans.second.begin(), i);
		}
	}
	return ans;
}

int main()
{
	while (cin >> n&&n)
	{
		a.clear();
		FOR(i, n)
		{
			food f;
			cin >> f.name >> f.w >> f.s;
			a.push_back(f);
		}
		P ans = calc(0, INT_MAX, 0, 0);
		FOR(i, n)
		{
			cout << a[ans.second[i]].name << endl;
		}
	}
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

struct food{
	string n;
	int w;
	int s;
	int used;
};

int main(void){
	int n;
	while(cin>>n,n){
		vector<food> vf;
		rep(i,n){
			food f;
			cin >> f.n >> f.w >> f.s;
			f.used = 0;
			vf.push_back(f);
		}
		
		int weight = 0 ;
		rep(i,n)weight += vf[i].w;
		rep(i,n){
			vi vec;
			rep(j,n){
				if(!vf[j].used && vf[j].s >= weight - vf[j].w){
					vec.push_back(j);
				}
			}
			int wmax = -1;
			int u;
			rep(j,vec.size()){
				if(wmax < vf[vec[j]].w){
					wmax = vf[vec[j]].w;
					u = vec[j];
				}
			}
			cout<< vf[u].n << endl;
			vf[u].used = 1;
			weight -= vf[u].w;
			
		}
	}

}