Problem:


		
Problem B: Make Purse Light

		

			Mr. Bill は店で買い物をしている。 彼の財布にはいくらかの硬貨（10 円玉、50 円玉、100 円玉、500 円玉）が入っているが、彼は今この小銭をできるだけ消費しようとしている。 つまり、適切な枚数の硬貨によって品物の代金を払うことで、釣り銭を受け取った後における硬貨の合計枚数を最小にしようとしている。
		

		

			幸いなことに、この店の店員はとても律儀かつ親切であるため、釣り銭は常に最適な方法で渡される。 したがって、例えば 1 枚の 500 円玉の代わりに 5 枚の 100 円玉が渡されるようなことはない。 また、例えば 10 円玉を 5 枚出して、50 円玉を釣り銭として受け取ることもできる。 ただし、出した硬貨と同じ種類の硬貨が釣り銭として戻ってくるような払いかたをしてはいけない。 例えば、10 円玉を支払いの際に出したにも関わらず、別の 10 円玉が釣り銭として戻されるようでは、完全に意味のないやりとりが発生してしまうからである。
		

		

			ところが Mr. Bill は計算が苦手なため、実際に何枚の硬貨を使用すればよいかを彼自身で求めることができなかった。 そこで、彼はあなたに助けを求めてきた。 あなたの仕事は、彼の財布の中にある硬貨の枚数と支払い代金をもとに、使用すべき硬貨の種類と枚数を求めるプログラムを書くことである。なお、店員はお釣りに紙幣を使用することはない。
		
Input

		

			入力にはいくつかのテストケースが含まれる。
		

		

			それぞれのテストケースは 2 行から構成される。 1 行目には Mr. Bill の支払い金額を円単位で表した 1 つの整数が含まれている。 2 行目には 4 つの整数が含まれており、それらは順に財布の中にある 10 円玉、50 円玉、100 円玉、500 円玉の枚数をそれぞれ表す。
		

		

			支払い金額は常に 10 円単位である。 すなわち、支払い金額の一円の位は常に 0 である。 また財布の中に、同じ種類の硬貨は最大で 20 枚までしかないと仮定してよい。 支払いが不可能なケースが入力中に与えられることはない。
		

		

			入力の終了は単一の 0 を含む行によって表される。
		

		
Output

		

			それぞれのテストケースについて、Mr. Bill が使用すべき硬貨の種類と枚数を出力せよ。
		

		

			出力の各行には 2 つの整数 ci 、ki が含まれる。これは支払いの際に ci 円玉を ki 枚使用することを意味している。
			複数種類の硬貨を使用する場合は、ci の小さいほうから順に、必要な行数だけ出力を行うこと。 下記の出力例を参考にせよ。
		

		

			なお、出力には余計なスペースを含めてはならない。 連続するテストケースの間は空行で区切ること。
		

		
Sample Input

		

160
1 1 2 0
160
1 0 2 10
0

		
Output for the Sample Input

		

10 1
50 1
100 1

10 1
100 2

1番目のデータ がある。
		

-->
		


Sample input:
160
1 1 2 0
160
1 0 2 10
0


Sample output:
10 1
50 1
100 1

10 1
100 2

Submission status: Wrong Answer

Solution code:
coins = [10, 50, 100, 500]

def oturi(a, b):
    s = b - a
    l = [0, 0, 0, 0]
    for i in reversed(range(4)):
        n = s // coins[i]
        s -= coins[i] * n
        l[i] = n
    return l

first = True
while True:
    value = int(input())
    if not value:
        break
    cs = list(map(int, input().split()))
   
    if first:
        first = False
    else:
        print()

    pay = [0, 0, 0, 0]
    pay_sum = 0
    for i, c in enumerate(cs):
       pay[i] += c
       pay_sum += coins[i] * c
       if pay_sum >= value:
           break
    o = oturi(value, pay_sum)
    for i, v in enumerate(o):
        pay[i] -= v
        if pay[i] < 0:
            pay[i] = 0
    for i, v in enumerate(pay):
        if v:
            print(coins[i], v)

Submission status: Wrong Answer

Solution code:
coins = (10,50,100,500)
isfirst = True
while 1:
    cost = int(raw_input())
    if cost == 0: break
    if not isfirst: print
    have = map(int,raw_input().split())

    budget = sum(map(lambda x,y:x*y, have,coins))
    change = budget-cost

    ans = [0]*4
    for i in reversed(range(4)):
        c = change/coins[i]
        ans[i] = c
        change -= c*ans[i]

    for i in range(4):
        if have[i]-ans[i] <= 0: continue
        print coins[i],have[i]-ans[i]

    isfirst = False

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from itertools import product
coins = [10,50,100,500]

def coin_count(num):
    count = 0
    for coin in sorted(coins,reverse = True):
        count += num // coin
        num -= (num // coin)*coin
    return count

while True:
    price = int(input())
    if price == 0:
        break
    has = list(map(int,input().split()))
    sum_coins = list(map(lambda x: x[0]*x[1], zip(has,coins)))

    has = [has[i] - ((sum_coins[i] - price)//coins[i]) if (sum_coins[i] - price) >= 0 else has[i] for i in range(4)]
    sum_coins = list(map(lambda x: x[0]*x[1], zip(has,coins)))

    change = (sum(sum_coins) - price)
    surplus = [change % 50 // 10, change % 100 // 50, change % 500 // 100, change // 500]

    for i in range(4):
        if has[i] > surplus[i]:
            print(coins[i],has[i] - surplus[i])
    print()

Submission status: Wrong Answer

Solution code:
yen = [10, 50, 100, 500]
while True:
    p = int(input())
    if p == 0:
        break
    coins = list(map(int, input().split()))
    pay = [0, 0, 0, 0]
    for i in range(3, -1, -1):
        pay[i] = min(p // yen[i], coins[i])
        p -= pay[i] * yen[i]
    for i in range(4):
        if pay[i] > 0:
            print(yen[i], pay[i])

Submission status: Wrong Answer

Solution code:
yen = [10, 50, 100, 500, 1000]
while True:
    p = int(input())
    if p == 0:
        break
    coins = list(map(int, input().split()))
    pay = [0, 0, 0, 0, 0]
    for i in range(4):
        pay[i] = min(p // yen[i], coins[i])
        p -= pay[i] * yen[i]
        while p % yen[i + 1] != 0:
            pay[i] -= 1
            p += yen[i]
    for i in range(4):
        if pay[i] > 0:
            print(yen[i], pay[i])
    print()

Submission status: Wrong Answer

Solution code:
yen = [10, 50, 100, 500, 1000]
flg = False
while True:
    p = int(input())
    if p == 0:
        break
    if flg :
        print()
    coins = list(map(int, input().split()))
    pay = [0, 0, 0, 0, 0]
    for i in range(4):
        pay[i] = min(p // yen[i], coins[i])
        p -= pay[i] * yen[i]
        while p % yen[i + 1] != 0:
            pay[i] -= 1
            p += yen[i]
    for i in range(4):
        if pay[i] > 0:
            print(yen[i], pay[i])
    flg = True

Submission status: Wrong Answer

Solution code:
yen = [10, 50, 100, 500, 1000]
flg = False
while True:
    p = int(input())
    if p == 0:
        break
    if flg:
        print()
    coins = list(map(int, input().split()))
    pay = [0, 0, 0, 0]
    for i in range(4):
        pay[i] = min(p // yen[i], coins[i])
        p -= pay[i] * yen[i]
        ni = i + 1
        # if p > 0:
        #     while coins[ni] == 0:
        #         ni += 1
        while p > 0 and p % yen[ni] != 0 :
            pay[i] -= 1
            p += yen[i]
    for i in range(4):
        if pay[i] > 0:
            print(yen[i], pay[i])
    flg = True

Submission status: Wrong Answer

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2007 "Make Purse Light"????§£??????
cs = [10, 50, 100, 500, 100000]
p = int(input())
while True:
    ns = list(map(int, input().split()))
    ks = [0] * 4
    for i in range(4):
        if not ns[i]:
            continue
        ks[i] = ns[i] - (cs[i] * ns[i] - p) % cs[i + 1] // cs[i]
        p -= cs[i] * ks[i]
        if ks[i]:
            print(cs[i], ks[i])
    p = int(input())
    if not p:
        break
    print("")

Submission status: Wrong Answer

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2007 "Make Purse Light"????§£??????
cs = [10, 50, 100, 500, 100000]
p = int(input())
while True:
    ns = list(map(int, input().split()))
    ks = [0] * 4
    for i in range(4):
        if not ns[i]:
            continue
        ks[i] = ns[i] - (cs[i] * ns[i] - p) % cs[i + 1] // cs[i]
        p -= cs[i] * ks[i]
        if ks[i]:
            print(cs[i], ks[i], p)
        if p <= 0:
            break
    p = int(input())
    if not p:
        break
    print("")

Submission status: Wrong Answer

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2007 "Make Purse Light"????§£??????
cs = [10, 50, 100, 500, 100000]
p = int(input())
while True:
    ns = list(map(int, input().split()))
    ks = [0] * 4
    for i in range(4):
        if not ns[i]:
            continue
        ks[i] = ns[i] - (cs[i] * ns[i] - p) % cs[i + 1] // cs[i]
        p -= cs[i] * ks[i]
        if ks[i]:
            print(cs[i], ks[i])
        if p <= 0:
            break
    p = int(input())
    if not p:
        break
    print("")

Submission status: Wrong Answer

Solution code:
c = [10,50,100,500,1000]
while 1:
    n = int(input())
    if n==0: break
    l = list(map(int,input().split()))
    for i,x in enumerate(l):
        if n<x: break
        m = n%(c[i+1])//c[i]
        if x==0: n += c[i]
        elif m<=x:
            n -= c[i]*m
            print(c[i],m)
    print()

Submission status: Wrong Answer

Solution code:
def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????

    :param fee:
    :param coin_values:
    :param coin_nums:
    :return:
    """
    # 1. 
    oturi = coin_values[0]*coin_nums[0]\
            +coin_values[1]*coin_nums[1]\
            +coin_values[2]*coin_nums[2]\
            +coin_values[3]*coin_nums[3]\
            -fee
    use_coins = [0] * len(coin_value)
    no_use_coins = [0]*len(coin_value)
    
    # 2.
    for i in range(len(coin_value)-1, 0, -1):
        no_use_coins[i] = int(oturi / coin_value[i])
        oturi = oturi - (coin_value[i] * no_use_coins[i])
    
    #3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(coin_value[i],' ',use_coins[i])

if __name__ == "__main__":
    total_fee = int(input('total_fee:'))
    coins = input('total_coins:')
    coins = coins.split(' ') #10, 50, 100, 500????????§????????????
    coins = [int(coin) for coin in coins]
    coin_value=[10, 50, 100, 500]
    back_oturigation(total_fee, coin_value, coins)

Submission status: Wrong Answer

Solution code:
# http://www.deqnotes.net/acmicpc/p0006/

def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0]*coin_nums[0]\
            +coin_values[1]*coin_nums[1]\
            +coin_values[2]*coin_nums[2]\
            +coin_values[3]*coin_nums[3]\
            -fee
    use_coins = [0] * len(coin_value)
    no_use_coins = [0]*len(coin_value)

    # 2.
    for i in range(len(coin_value)-1, -1, -1):
        no_use_coins[i] = int(oturi / coin_value[i])
        oturi = oturi - (coin_value[i] * no_use_coins[i])


    #3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(coin_value[i],' ',use_coins[i])

if __name__ == "__main__":
    total_fee = int(input('total_fee:'))
    coins = input('total_coins:')
    coins = coins.split(' ') #10, 50, 100, 500????????§????????????
    coins = [int(coin) for coin in coins]
    coin_value=[10, 50, 100, 500]
    back_oturigation(total_fee, coin_value, coins)

Submission status: Wrong Answer

Solution code:
def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0]*coin_nums[0]\
            +coin_values[1]*coin_nums[1]\
            +coin_values[2]*coin_nums[2]\
            +coin_values[3]*coin_nums[3]\
            -fee
    use_coins = [0] * len(coin_value)
    no_use_coins = [0]*len(coin_value)

    # 2.
    for i in range(len(coin_value)-1, -1, -1):
        no_use_coins[i] = int(oturi / coin_value[i])
        oturi = oturi - (coin_value[i] * no_use_coins[i])


    #3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_value[i])+' '+str(use_coins[i]))

if __name__ == "__main__":
    total_fee = int(input('total_fee:'))
    coins = input('total_coins:')
    coins = coins.split(' ') #10, 50, 100, 500????????§????????????
    coins = [int(coin) for coin in coins]
    coin_value=[10, 50, 100, 500]
    back_oturigation(total_fee, coin_value, coins)

Submission status: Wrong Answer

Solution code:
# http://www.deqnotes.net/acmicpc/p0006/

def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0]*coin_nums[0]\
            +coin_values[1]*coin_nums[1]\
            +coin_values[2]*coin_nums[2]\
            +coin_values[3]*coin_nums[3]\
            -fee
    use_coins = [0] * len(coin_value)
    no_use_coins = [0]*len(coin_value)

    # 2.
    for i in range(len(coin_value)-1, -1, -1):
        no_use_coins[i] = int(oturi / coin_value[i])
        oturi = oturi - (coin_value[i] * no_use_coins[i])


    #3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_value[i])+' '+str(use_coins[i]))

if __name__ == "__main__":
    total_fee = int(input('total_fee:'))
    coins = input('total_coins:')
    coins = coins.split(' ') #10, 50, 100, 500????????§????????????
    coins = [int(coin) for coin in coins]
    coin_value=[10, 50, 100, 500]
    back_oturigation(total_fee, coin_value, coins)

Submission status: Wrong Answer

Solution code:
def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ?????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ????????????§?????????????????????-> ??°?????????????????????¶???????????????????
    3. 2?????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0]*coin_nums[0]\
            +coin_values[1]*coin_nums[1]\
            +coin_values[2]*coin_nums[2]\
            +coin_values[3]*coin_nums[3]\
            -fee
    use_coins = [0] * len(coin_value)
    no_use_coins = [0]*len(coin_value)
 
    # 2.
    for i in range(len(coin_value)-1, -1, -1):
        no_use_coins[i] = int(oturi / coin_value[i])
        oturi = oturi - (coin_value[i] * no_use_coins[i])
 
 
    #3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(coin_value[i],' ',use_coins[i])
 
if __name__ == "__main__":
    total_fee = int(input('total_fee:'))
    coins = input('total_coins:')
    coins = coins.split(' ') #10, 50, 100, 500?????????§????????????
    coins = [int(coin) for coin in coins]
    coin_value=[10, 50, 100, 500]
    back_oturigation(total_fee, coin_value, coins)

Submission status: Wrong Answer

Solution code:
# http://www.deqnotes.net/acmicpc/p0006/
import re


# def check_testcase():
#     with open('./2007-input.txt') as f:
#         input_testcase = f.read()
#     with open('./2007-output.txt') as f:
#         pre_output_testcase = f.read()
#     input_testcase = input_testcase.splitlines()
#     pre_output_testcase = re.findall('([0-9]*\s[0-9]*)(?=\n)', pre_output_testcase)
#
#     output_testcase = [''] * int(len(input_testcase) / 2)
#     cnt = 0
#     for x in pre_output_testcase:
#         if x == '\n':
#             cnt += 1
#         else:
#             output_testcase[cnt] = output_testcase[cnt] + x + '\n'
#
#     for i in range(0, len(output_testcase), 1):
#         fee = int(input_testcase[i * 2])
#         coin = [int(x) for x in input_testcase[i * 2 + 1].split(' ')]
#         coin_value = [10, 50, 100, 500]
#
#         result = back_oturigation(fee, coin_value, coin)
#
#         if result == output_testcase[i]:
#             print("PASS")
#         else:
#             import ipdb;
#             ipdb.set_trace()


def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0] * coin_nums[0] \
            + coin_values[1] * coin_nums[1] \
            + coin_values[2] * coin_nums[2] \
            + coin_values[3] * coin_nums[3] \
            - fee
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)

    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])

    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + ' ' + str(use_coins[i]))

if __name__ == "__main__":
    total_fee = int(input('total_fee:'))

    #while (total_fee != 0):
    coins = input('total_coins:')
    coins = coins.split(' ')  # 10, 50, 100, 500????????§????????????
    coins = [int(coin) for coin in coins]
    coin_values = [10, 50, 100, 500]
    back_oturigation(total_fee, coin_values, coins)

Submission status: Wrong Answer

Solution code:
# http://www.deqnotes.net/acmicpc/p0006/
import re


# def check_testcase():
#     with open('./2007-input.txt') as f:
#         input_testcase = f.read()
#     with open('./2007-output.txt') as f:
#         pre_output_testcase = f.read()
#     input_testcase = input_testcase.splitlines()
#     pre_output_testcase = re.findall('([0-9]*\s[0-9]*)(?=\n)', pre_output_testcase)
#
#     output_testcase = [''] * int(len(input_testcase) / 2)
#     cnt = 0
#     for x in pre_output_testcase:
#         if x == '\n':
#             cnt += 1
#         else:
#             output_testcase[cnt] = output_testcase[cnt] + x + '\n'
#
#     for i in range(0, len(output_testcase), 1):
#         fee = int(input_testcase[i * 2])
#         coin = [int(x) for x in input_testcase[i * 2 + 1].split(' ')]
#         coin_value = [10, 50, 100, 500]
#
#         result = back_oturigation(fee, coin_value, coin)
#
#         if result == output_testcase[i]:
#             print("PASS")
#         else:
#             import ipdb;
#             ipdb.set_trace()


def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0] * coin_nums[0] \
            + coin_values[1] * coin_nums[1] \
            + coin_values[2] * coin_nums[2] \
            + coin_values[3] * coin_nums[3] \
            - fee
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)

    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])

    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + ' ' + str(use_coins[i]))

if __name__ == "__main__":

    while (True):
        total_fee = int(input('total_fee:'))
        if total_fee == 0:
            break
        coins = input('total_coins:')
        coins = coins.split(' ')  # 10, 50, 100, 500????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)
    print('')

Submission status: Wrong Answer

Solution code:

def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0] * coin_nums[0] \
            + coin_values[1] * coin_nums[1] \
            + coin_values[2] * coin_nums[2] \
            + coin_values[3] * coin_nums[3] \
            - fee
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)

    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])

    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + ' ' + str(use_coins[i]))

if __name__ == "__main__":

    while (True):
        total_fee = int(input('total_fee:'))
        if total_fee == 0:
            break
        coins = input('total_coins:')
        coins = coins.split(' ')  # 10, 50, 100, 500????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)

Submission status: Wrong Answer

Solution code:

def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0] * coin_nums[0] \
            + coin_values[1] * coin_nums[1] \
            + coin_values[2] * coin_nums[2] \
            + coin_values[3] * coin_nums[3] \
            - fee
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)

    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])

    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + ' ' + str(use_coins[i]))

if __name__ == "__main__":
    first = True
    while (True):
        total_fee = int(input('ffff'))
        if total_fee == 0:
            break
        if first:
            first = False
        else:
            print('')
        coins = input('aaa')
        coins = coins.split(' ')  # 10, 50, 100, 500????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)

Submission status: Wrong Answer

Solution code:
def calc(c1,c2,c3,c4):
    return c1*10 + c2*50 + c3*100 + c4*500

def coindiff(p,c1,c2,c3,c4):
    n = c1+c2+c3+c4
    over = calc(c1,c2,c3,c4) - p
    n -= (over%50) // 10
    n -= (over%100) // 50
    n -= (over%500) // 100
    n -= over // 500
    return n

while True:
    N = int(input())
    if N == 0: break
    c1,c2,c3,c4 = map(int,input().split())
    maxdiff = -9999999
    ans = None
    for n1 in range(c1+1):
        for n2 in range(c2+1):
            for n3 in range(c3+1):
                n4 = (N - n1*10 + n2*50 + n3*100) // 500
                if n4 < 0: continue
                d = coindiff(N,n1,n2,n3,n4)
                if d > maxdiff:
                    maxdiff = d
                    ans = {10:n1,50:n2,100:n3,500:n4}
    for k,v in sorted(ans.items()):
        print('{0} {1}'.format(k, v))
    print('')

Submission status: Wrong Answer

Solution code:
def calc(c1,c2,c3,c4):
    return c1*10 + c2*50 + c3*100 + c4*500

def coindiff(p,c1,c2,c3,c4):
    n = c1+c2+c3+c4
    over = calc(c1,c2,c3,c4) - p
    n -= (over%50) // 10
    n -= (over%100) // 50
    n -= (over%500) // 100
    n -= over // 500
    return n

first = True
while True:
    N = int(input())
    if N == 0: break
    if first:
        first = False
    else:
        print('')
    c1,c2,c3,c4 = map(int,input().split())
    s1 = (N//10) % 5
    maxdiff = -9999999
    ans = {}
    for n1 in range(s1,c1+1,5):
        for n2 in range(c2+1):
            rem2 = N - n1*10 - n2*50
            for n3 in range(c3+1):
                rem3 = rem2 - n3*100
                n4 = max(0, (rem3-1)//500 + 1)
                d = coindiff(N,n1,n2,n3,n4)
                if d > maxdiff:
                    maxdiff = d
                    ans = {10:n1,50:n2,100:n3,500:n4}
    for k,v in sorted(ans.items()):
        if v == 0: continue
        print('{0} {1}'.format(k, v))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import math

n=int(input())
while n!=0:
    x={}
    y={10:0,50:0,100:0,500:0}
    x[10],x[50],x[100],x[500]=map(int,input().split())
    print(x)
    
    #import pdb; pdb.set_trace()

    #10円の処理
    if x[10]>=n/10:
        y[10]=n/10
    else:
        r=(n%50)/10
        y[10]=(x[10]-r)//5*5+r
    n-=y[10]*10

    #50円の処理
    if x[50]>=n/50:
        y[50]=math.ceil(n/50)
    else:
        if x[50]%2==(n/50)%2:
            y[50]=x[50]
        elif x[50]!=0:
            y[50]=x[50]-1
    n-=y[50]*50

    #100円の処理
    if x[100]>=n/100:
        y[100]=math.ceil(n/100)
    else:
        r=(n%500)/100
        y[100]=(x[100]-r)//5*5+r
    n-=y[100]*100
    
    #500円の処理 
    y[500]=math.ceil(n/500)
    
    #出力
    for k in y:
        if y[k]!=0:
            print(k,int(y[k]))
    
    print()
    n=int(input())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import math
n=int(input())
while n!=0:
    x={}
    y={10:0,50:0,100:0,500:0}
    x[10],x[50],x[100],x[500]=map(int,input().split())
    
    #import pdb; pdb.set_trace()

    #10円の処理
    if x[10]>=n/10:
        y[10]=n/10
    else:
        r=(n%50)/10
        y[10]=(x[10]-r)//5*5+r
    n-=y[10]*10

    #50円の処理
    if x[50]>=n/50:
        y[50]=math.ceil(n/50)
    else:
        if x[50]%2==(n/50)%2:
            y[50]=x[50]
        elif x[50]!=0:
            y[50]=x[50]-1
    n-=y[50]*50

    #100円の処理
    if x[100]>=n/100:
        y[100]=math.ceil(n/100)
    else:
        r=(n%500)/100
        y[100]=(x[100]-r)//5*5+r
    n-=y[100]*100
    
    #500円の処理 
    y[500]=math.ceil(n/500)
    
    #出力
    for k in y:
        if y[k]!=0:
            print(k,int(y[k]))
    
    print()
    n=int(input())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import math
n=int(input())
flag=False
while n!=0:
    if flag:
        print()
    x={}
    y={10:0,50:0,100:0,500:0}
    x[10],x[50],x[100],x[500]=map(int,input().split())
    
    #import pdb; pdb.set_trace()

    #10円の処理
    if x[10]>=n/10:
        y[10]=n/10
    else:
        r=(n%50)/10
        y[10]=(x[10]-r)//5*5+r
    n-=y[10]*10

    #50円の処理
    if x[50]>=n/50:
        y[50]=math.ceil(n/50)
    else:
        if x[50]%2==(n/50)%2:
            y[50]=x[50]
        elif x[50]!=0:
            y[50]=x[50]-1
    n-=y[50]*50

    #100円の処理
    if x[100]>=n/100:
        y[100]=math.ceil(n/100)
    else:
        r=(n%500)/100
        y[100]=(x[100]-r)//5*5+r
    n-=y[100]*100
    
    #500円の処理 
    y[500]=math.ceil(n/500)
    
    #出力
    for k in y:
        if y[k]!=0:
            print(k,int(y[k]))
    
    flag=True
    n=int(input())

Submission status: Wrong Answer

Solution code:
while 1:
    n=int(input())
    if not n:break
    t=n
    p=(10,50,100,500)
    l=map(int,input().split())
    u=[0,0,0,0]
    for (i,j) in enumerate(l):
        if j<=t//p[i]:
            u[i]+=j
            t-=j*p[i]
        else:
            if t%p[i]:
                u[i]+=t//p[i]+1
                t-=p[i]*(t//p[i]+1)
            else:
                u[i]+=t//p[i]
                t-=p[i]*(t//p[i])
            break
    [print(i,j) for (i,j) in zip(p,u) if j]

Submission status: Wrong Answer

Solution code:
def coin(n):
    return n / 500 + (n % 500) / 100 + (n % 100) / 50 + (n % 50) / 10

ret = ''

while True:
    n = int(raw_input())
    if n == 0:
        break
    c10, c50, c100, c500 = map(int, raw_input().split())

Submission status: Time Limit Exceeded

Solution code:
class charge:
    def __init__(self,x,y,z,v):
        self.coins = {10:x,50:y,100:z,500:v}
    def get_sum(self):
        return self.coins[10]*10 + self.coins[50]*50+self.coins[100]*100 + self.coins[500]*500
    def how_sheet(self):
        return self.coins[10] + self.coins[50] +self.coins[100] + self.coins[500]


def cal_charge(price,payment):
    a =[0,0,0,0]
    temp = payment - price
    if temp //500 !=0:
        a[3] = temp // 500
        temp = temp % 500
    if temp //100 !=0:
        a[2] = temp // 100
        temp = temp % 100
    if price //50 !=0:
        a[1] = temp // 50
        temp = temp % 50
    a[0] = temp //10
    return charge(*a)

if __name__ == "__main__":
    c =0
    while 1:
        price = int(input())
        if price ==0:break
        if c !=0:print("")
        max10,max50,max100,max500 = list(map(int,input().split(" ")))
        ans  = charge(max10,max50,max100,max500)
        minsh =  max10+max50+max100+max500
        i =0
        while i <= max500:
            j =0
            while  j <= max100:
                k =0
                while k <= max50:
                    l =0
                    while l <= max10:
                        payment = 500*i + 100*j +50*k + 10*l
                        if payment >= price:
                            temp = cal_charge(price,payment)
                            if minsh > temp.how_sheet():
                                minsh = temp.how_sheet()
                                ans = charge(l,k,j,i)
                        l +=1
                    k +=1
                j +=1
            i +=1
        for i in [10,50,100,500]:
            if ans.coins[i] !=0 :print("{} {}".format(i,ans.coins[i]))
        c +=1

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
def charge(price,payment):
    val =[0,0,0,0]
    coins = [500,100,50,10]
    rem = payment - price
    for i in range(4):
        val[i] =rem //coins[i]
        rem = rem%coins[i]
    return sum(val)
count =0
while 1:
    price = int(input())
    if price ==0:break
    if count !=0:print(' ')
    max10,max50,max100,max500 = list(map(int,input().split(' ')))
    ans = (max10,max50,max100,max500)
    mincharge = max10+max50+max100+max500
    temp10 = [i for i in range(max10+1)]
    temp50 = [i for i in range(max50+1)]
    temp100 = [i for i in range(max100+1)]
    temp500 = [i for i in range(max500+1)]
    combinations = list(it.product(temp10,temp50,temp100,temp500))
    for com in combinations:
        pay= com[0]*10+com[1]*50+com[2]*100+com[3]*500
        if price> pay:continue
        temp = charge(price,pay)
        if mincharge > temp:
            mincharge = temp
            ans = com
    p = [10,50,100,500]
    for i in range(4):
        if ans[i] !=0:print("{} {}".format(p[i],ans[i]))
    count+=1

Submission status: Accepted

Solution code:
count = 0
coins =[10,50,100,500]
while 1:
    price = int(input())
    if price ==0:break
    if count !=0:print('')
    wallet= list(map(int,input().split(' ')))
    cash = wallet[0]* 10 + wallet[1] * 50 + wallet[2] * 100 + wallet[3] * 500
    charge = cash - price
    chargecoins = ((charge % 50) // 10,(charge % 100)//50,(charge % 500)//100,charge // 500)
    for  i in range(4):
        if wallet[i] > chargecoins[i]:print('{} {}'.format(coins[i],wallet[i]-chargecoins[i]))
    count +=1