-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2355.cpp
43 lines (36 loc) · 928 Bytes
/
2355.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <string>
#include <vector>
using namespace std;
class Solution
{
public:
long long maximumBooks(vector<int> &books) {
const int N = books.size();
// auto dp = vector<unsigned long>(N, 0);
long long mx = 0;
for (auto i = 0; i < N; i++) {
long long sum = 0;
for (int j = i; j < N; j++) {
if (books[j] < books[i]) {
continue;
} else {
sum += books[j];
}
}
mx = max(mx, sum);
/*
if (i == 0) {
dp[i] = books[i];
continue;
}
if (books[i] <= books[i - 1]) {
dp[i] = books[i];
} else {
dp[i] = dp[i - 1] + books[i];
}
mx = dp[i] > mx ? dp[i] : mx;
*/
}
return mx;
}
};