classATM:def__init__(self):self.cnt=[0]*5self.d=[20,50,100,200,500]defdeposit(self,banknotesCount:List[int])->None:fori,vinenumerate(banknotesCount):self.cnt[i]+=vdefwithdraw(self,amount:int)->List[int]:ans=[0]*5foriinrange(4,-1,-1):ans[i]=min(amount//self.d[i],self.cnt[i])amount-=ans[i]*self.d[i]ifamount>0:return[-1]fori,vinenumerate(ans):self.cnt[i]-=vreturnans# Your ATM object will be instantiated and called as such:# obj = ATM()# obj.deposit(banknotesCount)# param_2 = obj.withdraw(amount)
classATM{privatelong[]cnt=newlong[5];privateint[]d={20,50,100,200,500};publicATM(){}publicvoiddeposit(int[]banknotesCount){for(inti=0;i<banknotesCount.length;++i){cnt[i]+=banknotesCount[i];}}publicint[]withdraw(intamount){int[]ans=newint[5];for(inti=4;i>=0;--i){ans[i]=(int)Math.min(amount/d[i],cnt[i]);amount-=ans[i]*d[i];}if(amount>0){returnnewint[]{-1};}for(inti=0;i<5;++i){cnt[i]-=ans[i];}returnans;}}/** * Your ATM object will be instantiated and called as such: * ATM obj = new ATM(); * obj.deposit(banknotesCount); * int[] param_2 = obj.withdraw(amount); */
classATM{public:ATM(){}voiddeposit(vector<int>banknotesCount){for(inti=0;i<banknotesCount.size();++i){cnt[i]+=banknotesCount[i];}}vector<int>withdraw(intamount){vector<int>ans(5);for(inti=4;~i;--i){ans[i]=min(1ll*amount/d[i],cnt[i]);amount-=ans[i]*d[i];}if(amount>0){return{-1};}for(inti=0;i<5;++i){cnt[i]-=ans[i];}returnans;}private:longlongcnt[5]={0};intd[5]={20,50,100,200,500};};/** * Your ATM object will be instantiated and called as such: * ATM* obj = new ATM(); * obj->deposit(banknotesCount); * vector<int> param_2 = obj->withdraw(amount); */
typeATMstruct{d[5]intcnt[5]int}funcConstructor()ATM{returnATM{[5]int{20,50,100,200,500},[5]int{}}}func(this*ATM)Deposit(banknotesCount[]int){fori,v:=rangebanknotesCount{this.cnt[i]+=v}}func(this*ATM)Withdraw(amountint)[]int{ans:=make([]int,5)fori:=4;i>=0;i--{ans[i]=min(amount/this.d[i],this.cnt[i])amount-=ans[i]*this.d[i]}ifamount>0{return[]int{-1}}fori,v:=rangeans{this.cnt[i]-=v}returnans}/** * Your ATM object will be instantiated and called as such: * obj := Constructor(); * obj.Deposit(banknotesCount); * param_2 := obj.Withdraw(amount); */
classATM{privatecnt:number[];privated:number[];constructor(){this.cnt=[0,0,0,0,0];this.d=[20,50,100,200,500];}deposit(banknotesCount:number[]):void{for(leti=0;i<banknotesCount.length;i++){this.cnt[i]+=banknotesCount[i];}}withdraw(amount:number):number[]{letans=[0,0,0,0,0];for(leti=4;i>=0;i--){ans[i]=Math.min(Math.floor(amount/this.d[i]),this.cnt[i]);amount-=ans[i]*this.d[i];}if(amount>0){return[-1];}for(leti=0;i<ans.length;i++){this.cnt[i]-=ans[i];}returnans;}}/** * Your ATM object will be instantiated and called as such: * var obj = new ATM() * obj.deposit(banknotesCount) * var param_2 = obj.withdraw(amount) */