Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Books You Can Take

Try to solve the Maximum Number of Books You Can Take problem.

Statement

You are given an integer array books indexed from 00, where books[i] denotes the number of books available on the ithi^{ {th}} shelf.

You want to collect books from a contiguous segment of shelves from index l to index r, where 0≤l≤r<0 \leq l \leq r < books.length. For each shelf i in the range from l to r, you can take c[i]c[i] books such that:

  • 1≤c[i]≤1 \leq c[i] \leq books[i] for all l≤i≤rl \leq i \leq r

  • c[i]<c[i+1]c[i] < c[i + 1] for all l≤i<rl \leq i < r

Return the maximum total number of books you can collect.

Constraints:

  • 1≤1 \leq books.length ≤105\leq 10^5

  • 0≤0 \leq books[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Books You Can Take

Try to solve the Maximum Number of Books You Can Take problem.

Statement

You are given an integer array books indexed from 00, where books[i] denotes the number of books available on the ithi^{ {th}} shelf.

You want to collect books from a contiguous segment of shelves from index l to index r, where 0≤l≤r<0 \leq l \leq r < books.length. For each shelf i in the range from l to r, you can take c[i]c[i] books such that:

  • 1≤c[i]≤1 \leq c[i] \leq books[i] for all l≤i≤rl \leq i \leq r

  • c[i]<c[i+1]c[i] < c[i + 1] for all l≤i<rl \leq i < r

Return the maximum total number of books you can collect.

Constraints:

  • 1≤1 \leq books.length ≤105\leq 10^5

  • 0≤0 \leq books[i] ≤105\leq 10^5