/*
    第2種情報処理技術者試験    平成10年度・秋期・午後 問7
                                BohYoh Shibata PREPARATION
*/

#define TBLSIZE 5
static int money[] = {1000, 500, 100, 50, 10},
           stock[] = {0, 10, 10, 10, 10};

int VendingMachine(int price, int input[], int output[])
{
    int change, k, paid, retval;

    paid = 0;
    for(k = 0; k < TBLSIZE; k++) {
        paid += input[k] * money[k];
    }
    change = paid - price;

    if (change != 0) {
        for( k = 0; k < TBLSIZE; k++ ) {
            output[k] = change / money[k] ;
            if (output[k] > stock[k])
                output[k] = stock[k];
            change -= output[k] * money[k];
        }

        if ( change > 0 ) {
            for(k = 0; k < TBLSIZE; k++)
                output[k] = input[k];
            retval = -1;
        } else {
            for(k = 0; k < TBLSIZE; k++)
                stock[k] = stock[k] + input[k] - output[k] ;
            retval = 1;
        }
    } else {
        for(k = 0; k < TBLSIZE; k++) {
            output[k] = 0;
            stock[k] += input[k];
        }
        retval = 0;
    }
    return retval;
}