Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int maxlen(vector<int> v)
- {
- int hi = n, lo = 1, ans = -1, mid, cnt = 0;
- while(lo <= hi) {
- mid = hi+lo>>1;
- if(cnt = count(mid)) {
- ans = mid;
- lo = mid + 1;
- } else {
- hi = mid - 1;
- }
- }
- int count(int len) {
- int cnt = 0;
- for(int i = len; i <= n; i++)
- if(prefixsum[i] - prefixsum[i - len] > K)
- cnt++;
- return cnt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement