Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- int solution(vector<int> &A) {
- vector<int> st(A.size() + 1);
- st[0] = A[0];
- int last_max = 0;
- for (size_t i = 1; i < A.size(); i++) {
- st[i] = max(st[i - 1], st[last_max]) + A[i];
- st[last_max] = max(st[last_max], st[i - 1]);
- if (i - last_max >= 6) {
- last_max++;
- for (int j = last_max + 1, k = last_max + 6; j < k; j++) {
- if (st[j] > st[last_max]) {
- last_max = j;
- }
- }
- }
- }
- return st[A.size() - 1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement