class ATM:
    def __init__(self):
        self.cash = [0] * 5
        self.values = [20, 50, 100, 200, 500]

    def deposit(self, banknotes_count: List[int]) -> None:
        for i, n in enumerate(banknotes_count):
            self.cash[i] += n

    def withdraw(self, amount: int) -> List[int]:
        res = []
        for val, n in zip(self.values[::-1], self.cash[::-1]):
            need = min(n, amount // val)
            res = [need] + res
            amount -= (need * val)
        if amount == 0:
            self.deposit([-x for x in res])
            return res
        else:
            return [-1]
class ATM {
	long[] notes = new long[5];                                                // Note: use long[] instead of int[] to avoid getting error in large testcases
	int[] denoms;
	public ATM() {
		denoms = new int[]{ 20,50,100,200,500 };                               // create an array to represent money value.
	}

	public void deposit(int[] banknotesCount) {
		for(int i = 0; i < banknotesCount.length; i++){
			notes[i] += banknotesCount[i];                                       // add new deposit money to existing
		}
	}

	public int[] withdraw(int amount) {                 
		int[] result = new int[5];                                              // create result array to store quantity of each notes we will be using to withdraw "amount"
		for(int i = 4; i >= 0; i--){
			if(amount >= denoms[i] ){                                              
				int quantity = (int) Math.min(notes[i], amount / denoms[i]);     // pick the minimum quanity. because if say, amount/denoms[i] gives 3 but you only have 1 note. so you have to use 1 only instead of 3 
				amount -= denoms[i] * quantity;                                 // amount left = 100
				result[i] = quantity;
			}
		}
		if(amount != 0){ return new int[]{-1}; }
		for(int i = 0; i < 5; i++){  notes[i] -= result[i];  }                   // deduct the quantity we have used.
		return result;
	}
}
Design an ATM Machine
There is an ATM machine that stores banknotes of 5 denominations: 20, 50, 100, 200, and 500 dollars. Initially the ATM is empty. The user can use the machine to deposit or withdraw any amount of money.

When withdrawing, the machine prioritizes using banknotes of larger values.


	For example, if you want to withdraw $300 and there are 2 $50 banknotes, 1 $100 banknote, and 1 $200 banknote, then the machine will use the $100 and $200 banknotes.
	However, if you try to withdraw $600 and there are 3 $200 banknotes and 1 $500 banknote, then the withdraw request will be rejected because the machine will first try to use the $500 banknote and then be unable to use banknotes to complete the remaining $100. Note that the machine is not allowed to use the $200 banknotes instead of the $500 banknote.


Implement the ATM class:


	ATM() Initializes the ATM object.
	void deposit(int[] banknotesCount) Deposits new banknotes in the order $20, $50, $100, $200, and $500.
	int[] withdraw(int amount) Returns an array of length 5 of the number of banknotes that will be handed to the user in the order $20, $50, $100, $200, and $500, and update the number of banknotes in the ATM after withdrawing. Returns [-1] if it is not possible (do not withdraw any banknotes in this case).


&nbsp;
Example 1:

Input
["ATM", "deposit", "withdraw", "deposit", "withdraw", "withdraw"]
[[], [[0,0,1,2,1]], [600], [[0,1,0,1,1]], [600], [550]]
Output
[null, null, [0,0,1,0,1], null, [-1], [0,1,0,0,1]]

Explanation
ATM atm = new ATM();
atm.deposit([0,0,1,2,1]); // Deposits 1 $100 banknote, 2 $200 banknotes,
                          // and 1 $500 banknote.
atm.withdraw(600);        // Returns [0,0,1,0,1]. The machine uses 1 $100 banknote
                          // and 1 $500 banknote. The banknotes left over in the
                          // machine are [0,0,0,2,0].
atm.deposit([0,1,0,1,1]); // Deposits 1 $50, $200, and $500 banknote.
                          // The banknotes in the machine are now [0,1,0,3,1].
atm.withdraw(600);        // Returns [-1]. The machine will try to use a $500 banknote
                          // and then be unable to complete the remaining $100,
                          // so the withdraw request will be rejected.
                          // Since the request is rejected, the number of banknotes
                          // in the machine is not modified.
atm.withdraw(550);        // Returns [0,1,0,0,1]. The machine uses 1 $50 banknote
                          // and 1 $500 banknote.

&nbsp;
Constraints:


	banknotesCount.length == 5
	0 &lt;= banknotesCount[i] &lt;= 109
	1 &lt;= amount &lt;= 109
	At most 5000 calls in total will be made to withdraw and deposit.
	At least one call will be made to each function withdraw and deposit.


var ATM = function() {
    this.bankNotes = new Array(5).fill(0)
    this.banksNotesValue = [20, 50, 100, 200, 500]
};

/**
 * @param {number[]} banknotesCount
 * @return {void}
 */
ATM.prototype.deposit = function(banknotesCount) {
    for (let i = 0; i < 5; i++) {
       this.bankNotes[i] += banknotesCount[i]
    }
    return this.bankNotes
};

/**
 * @param {number} amount
 * @return {number[]}
 */
ATM.prototype.withdraw = function(amount) {
    let remain = amount
    let usedBankNotes = new Array(5).fill(0)
    let temp = [...this.bankNotes]
    for (let i = 4; i >= 0; i--) {
        if (temp[i] > 0 && remain >= this.banksNotesValue[i]) {
            const bankNote = Math.floor(remain / this.banksNotesValue[i])
            const maxCanUse = Math.min(temp[i], bankNote)
            usedBankNotes[i] = maxCanUse
            temp[i] -= maxCanUse

            remain -= maxCanUse * this.banksNotesValue[i]
        }
    }

    if (remain > 0) {
        return [-1]
    } else {
        this.bankNotes = temp
        return usedBankNotes
    }
};

/**
 * Your ATM object will be instantiated and called as such:
 * var obj = new ATM()
 * obj.deposit(banknotesCount)
 * var param_2 = obj.withdraw(amount)
 */
class ATM {
public:
    long long bank[5] = {}, val[5] = {20, 50, 100, 200, 500};
    void deposit(vector<int> banknotesCount) {
        for (int i = 0; i < 5; ++i)
            bank[i] += banknotesCount[i];
    }
    vector<int> withdraw(int amount) {
        vector<int> take(5);
        for (int i = 4; i >= 0; --i) {
            take[i] = min(bank[i], amount / val[i]);
            amount -= take[i] * val[i];
        }
        if (amount)
            return { -1 };
        for (int i = 0; i < 5; ++i)
            bank[i] -= take[i];            
        return take;
    }
};