|
+3
If we maintain a prefix sum array of the original array our problem breaks down to finding L & R points (where L <= R) such that prefSm[R]-prefSum[L-1] is maximum possible and R-L+1 (all elements within) is between a to b. We can iterate over all points (i = 1 to N) and fix R=i after that we just need to find a point L which is at least a distance away but not more than b distance. We can do this easily in quadratic time but to do so in linear time we will need to use the idea of sliding window maximum problem. We can delay pushing elements to our sliding window by a (keeping the intended gap of a) and maintain a size keeping only b-a+1 elements in the window hence fulfilling our second constraint. Now look at my solution, hopefully you will be able to understand it now: https://github.com/ankitpriyarup/CSES_ProblemSet_Solution/blob/master/2%20Sorting_and_Searching.md#maximum-subarray-sum-ii |
|
0
I'll keep updating the repository as I'll do more problems. For additional range query editorial you can refer: https://mirror.codeforces.com/blog/entry/77128 |
|
0
Thanks! I'll add reference links soon. |
|
0
prev has no use in that question, I was doing CSES problems in a sequence and one question before that wanted you to find shortest path nodes so for that I used prev. I've made all my CSES submissions public to github if you want to checkout that question refer: https://mirror.codeforces.com/blog/entry/77863 |
|
+4
I've solved the same problem recently with coincidentally the same idea as your's, here's my AC submission. https://paste.ubuntu.com/p/cKqC9Gfv6S/ |
|
0
During compiling use this time g++ -std=c++17 cprog.cpp Then after execution last line will show: I personally like this over writing some code |
|
На
25DinRatingDouble →
Looking for a group to do Mashup Contests Everyday [1500 — 1899], 6 лет назад
0
Count me in :D |
|
0
Seems interesting, I've never heard of such data structure can you share implementation? |
|
+6
Recently I've seen such problems on Atcoder & Codeforces contest https://mirror.codeforces.com/contest/1187/problem/E |
|
+11
Okay point taken! |
|
+7
Edit: Point taken jeez.. Probably those who are pupil or below shouldn't be allowed to post something (They can comment however). Just a thought don't bash on me now XD |
|
+1
Funniest thing I've seen whole day XD |