Difficulty in understanding the setter code in MINSUBAR of cook-off Dec 2017

@vijju123 Sir, I am sorry that I am creating a new thread on this topic.
Since I saw that you had posted doubts during the editorial of this problem,I decide to ask you.
In the solution of the setter,while performing the lower bound operation why are we subtracting 1 from K?As per my understanding,lower bound will return the pointer pointing to the first prefix sum that is >=prefix[j]-d.So we should be subtracting 1 only if the prefix[j]-d does not exist but we have an element >prefix[j]-d.So,we must go one element smaller to that because then that smaller element will satisfy the inequality.
Here is the link to the code of setter:https://s3.amazonaws.com/codechef_shared/download/Solutions/COOK89/Setter/MINSUBAR.cpp
Thanks in advance …

Because lower_bound(f + st, f + ed, mp(a[i] - d, INF)) - f will return position of element in 1-based indexing. Meaning first element will be give value 1 &etc. But arrays etc follow 0-based indexing, so its actual index in array will be one less.

ok…thanks Sir