You are viewing a single comment's thread. Return to all comments →
can anyone find my mistake ? I think it is quite simple.
string acessoryCollection(int L, int A, int N, int D) { long long ans=0; if(N<D) ans=-1; else if(D==1){ ans=L*A; } else{ int min=N-D+1; while(L>min){ if(A==0) { ans=-1; break; } ans+=min*A; A--; L-=min; } if(L>0 & A==0) ans=-1; else if(L>0) ans+=L*A; } //cout << ans<<endl; string str; while(ans>0){ str.push_back('0'+ans%10); ans=ans/10; } if(str.size()!=0){ reverse(str.begin(),str.end()); } if(ans==-1) return "SAD"; else return str; }
Seems like cookies are disabled on this browser, please enable them to open this website
Accessory Collection
You are viewing a single comment's thread. Return to all comments →
can anyone find my mistake ? I think it is quite simple.