Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0170

"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple
from itertools import permutations


def solve(items):
    total_weight = 0
    for i in items:
        total_weight += i.w

    best_ans = []
    best_gp = float('inf')
    # ???????????????????????????????????????????????°?????????????????§????????????
    for perm in permutations(items):
        ans = []
        squashed = False
        cw = 0
        gp = 0
        n = len(items)

        for p in perm:
            if p.s < cw:
                squashed = True
                break
            cw += p.w
            ans.append(p.name)
            gp += n * p.w
            n -= 1
        # ????????°???????????£?????´????????????????¨???????????????????????????????????????£?????????????????§????????????
        if not squashed:
            gp /= total_weight
            if gp < best_gp:
                best_gp = gp
                best_ans = ans[:]
    # ????????????????????????????????£??????????????§?????????????±?????????????????????????????????????????????????
    best_ans.reverse()
    return best_ans


item = namedtuple('item', ['name', 'w', 's'])
def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        items = []
        for _ in range(n):
            name, w, s = input().split()
            items.append(item(name, int(w), int(s)))

        result = solve(items)
        print('\n'.join(result))


if __name__ == '__main__':
    main(sys.argv[1:])

Fixed submission:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0170

"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple


def solve(items):
    from itertools import permutations
    total_weight = 0
    for i in items:
        total_weight += i.w
    best_ans = []
    best_gp = float('inf')
    # ???????????????????????????????????????????????°?????????????????§????????????
    for perm in permutations(items):
        ans = []
        squashed = False
        cw = 0
        gp = 0
        n = len(items)
        for p in perm:
            if p.s < cw:
                squashed = True
                break
            cw += p.w
            ans.append(p.name)
            gp += n * p.w
            n -= 1
        # ????????°???????????£?????´????????????????¨???????????????????????????????????????£?????????????????§????????????
        if not squashed:
            gp /= total_weight
            if gp < best_gp:
                best_gp = gp
                best_ans = ans[:]
    # ????????????????????????????????£??????????????§?????????????±?????????????????????????????????????????????????
    best_ans.reverse()
    return best_ans


def solve2(items):
    items.sort(key=lambda x:x.w, reverse=True) # ??????????????????????????????
    total_weight = 0            #  ??¢?????????????????????
    for i in items:
        total_weight += i.w
    ans = []
    # ?????£???????????¢??????????????????????????????????????????????????§???????????¢??????????????????????????????????????????????????????????????????????????¢?????????????????????????????§??°????????????
    while items:
        cap = [x.s - total_weight + x.w for x in items] #  ????????\??????????????¢?????????????????????????????¨????????°??????????????????????????????????????????????????????0??\?????????OK
        for i in range(len(items)):
            if cap[i] >= 0:     #  ??°???????????????????????????????????????????????????????????????????????????
                ans.append(items[i].name)
                i = items.pop(i)
                total_weight -= i.w #  ???????????¢?????????????????????????????????
                break
    return ans


item = namedtuple('item', ['name', 'w', 's'])
def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        items = []
        for _ in range(n):
            name, w, s = input().split()
            items.append(item(name, int(w), int(s)))
        result = solve2(items)
        print('\n'.join(result))


if __name__ == '__main__':
    main(sys.argv[1:])