classATM:def__init__(self):self.d=[20,50,100,200,500]self.m=len(self.d)self.cnt=[0]*self.mdefdeposit(self,banknotesCount:List[int])->None:fori,xinenumerate(banknotesCount):self.cnt[i]+=xdefwithdraw(self,amount:int)->List[int]:ans=[0]*self.mforiinreversed(range(self.m)):ans[i]=min(amount//self.d[i],self.cnt[i])amount-=ans[i]*self.d[i]ifamount>0:return[-1]fori,xinenumerate(ans):self.cnt[i]-=xreturnans# Your ATM object will be instantiated and called as such:# obj = ATM()# obj.deposit(banknotesCount)# param_2 = obj.withdraw(amount)
classATM{privateint[]d={20,50,100,200,500};privateintm=d.length;privatelong[]cnt=newlong[5];publicATM(){}publicvoiddeposit(int[]banknotesCount){for(inti=0;i<banknotesCount.length;++i){cnt[i]+=banknotesCount[i];}}publicint[]withdraw(intamount){int[]ans=newint[m];for(inti=m-1;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<m;++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(m);for(inti=m-1;~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<m;++i){cnt[i]-=ans[i];}returnans;}private:staticconstexprintd[5]={20,50,100,200,500};staticconstexprintm=size(d);longlongcnt[m]={0};};/** * Your ATM object will be instantiated and called as such: * ATM* obj = new ATM(); * obj->deposit(banknotesCount); * vector<int> param_2 = obj->withdraw(amount); */
vard=[...]int{20,50,100,200,500}constm=len(d)typeATM[m]intfuncConstructor()ATM{returnATM{}}func(this*ATM)Deposit(banknotesCount[]int){fori,x:=rangebanknotesCount{this[i]+=x}}func(this*ATM)Withdraw(amountint)[]int{ans:=make([]int,m)fori:=m-1;i>=0;i--{ans[i]=min(amount/d[i],this[i])amount-=ans[i]*d[i]}ifamount>0{return[]int{-1}}fori,x:=rangeans{this[i]-=x}returnans}/** * Your ATM object will be instantiated and called as such: * obj := Constructor(); * obj.Deposit(banknotesCount); * param_2 := obj.Withdraw(amount); */
constd:number[]=[20,50,100,200,500];constm=d.length;classATM{privatecnt:number[];constructor(){this.cnt=Array(m).fill(0);}deposit(banknotesCount:number[]):void{for(leti=0;i<banknotesCount.length;++i){this.cnt[i]+=banknotesCount[i];}}withdraw(amount:number):number[]{constans:number[]=Array(m).fill(0);for(leti=m-1;i>=0;--i){ans[i]=Math.min(Math.floor(amount/d[i]),this.cnt[i]);amount-=ans[i]*d[i];}if(amount>0){return[-1];}for(leti=0;i<m;++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) */