Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <vector>
  2. int solution(vector<int> &A) {
  3.  
  4. vector<int> st(A.size() + 1);
  5. st[0] = A[0];
  6. int last_max = 0;
  7.  
  8. for (size_t i = 1; i < A.size(); i++) {
  9. st[i] = max(st[i - 1], st[last_max]) + A[i];
  10. st[last_max] = max(st[last_max], st[i - 1]);
  11.  
  12. if (i - last_max >= 6) {
  13. last_max++;
  14. for (int j = last_max + 1, k = last_max + 6; j < k; j++) {
  15. if (st[j] > st[last_max]) {
  16. last_max = j;
  17. }
  18. }
  19. }
  20. }
  21. return st[A.size() - 1];
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement