c++ - k is a given value. a is array . Reducing i times when k> a[i] Any better way to do the code.Its taking long time for larger value -
k given value. array . reducing times when k> a[i] better way code.its taking long time larger value.
long int buymaximumproducts(long int n, long int k, int* a) { long int count = 0; (int = 1; <= n; i++) { if (k < a[i]) { break; } (int j = 1; j <= i; j++) { if (k < a[i]) { break; } k = k - a[i]; ++count; } } return count; }
Comments
Post a Comment