Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
561 B
3
Indexable
Never
using namespace std;

int numbersofProduct(int n, int x, int arr[]) // N is number of products, x is the budget she has and arr is on array of
{
  int items = 0;
  int current_sum = 0;

  for (int i = 0; i < n; i++) {
    if (current_sum + arr[i] <= x) {
      current_sum += arr[i];
      items++;
    } else {
      current_sum = 0;
    }
  }

  return items;
}

int main() {
  int n, x;
  cin >> n >> x;
  int values[n];

  for (int i = 0; i < n; i++) {
    cin >> values[i];
  }

  cout << numbersofProduct(n, x, values);

  return 0;
}
 

2 wale ka mila ye