Coordinate Compression

All submissions for this problem are available.
Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well.
You are given a sequence of integers $A_1, A_2, \dots, A_N$. For an integer $K$, let's define a *$K$compressed* sequence $B_1, B_2, \dots, B_N$ as follows:  for each valid $i$, $B_i$ is a positive integer  for each valid $i$, if there are exactly $X$ numbers smaller than or equal to $A_i$ in the subsequence $A_{\mathop{max}(1, iK)}, \dots, A_{\mathop{min}(N, i+K)}$, then there must be exactly $X$ numbers smaller than or equal to $B_i$ in the subsequence $B_{\mathop{max}(1, iK)}, \dots, B_{\mathop{min}(N, i+K)}$  $B_1 + B_2 + \dots + B_N$ is minimum possible You may notice that for $K = N1$ or $K = N$, this becomes the wellknown technique of coordinate compression. For example, consider the sequence $A = [4, 2, 8, 1, 4, 3, 8, 1]$. If we choose $K = 1$, then the $K$compressed sequence will be $B = [2, 1, 2, 1, 2, 1, 2, 1]$. The sum of its elements is $12$, which is the minimum. For a given integer $S$, find the number of values of $K$ ($0 \le K \le N$) such that the sum of elements of the $K$compressed sequence does not exceed $S$. ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains two spaceseparated integers $N$ and $S$.  The second line contains $N$ spaceseparated integers $A_1, A_2, \dots, A_N$. ### Output For each test case, print a single line containing one integer — the number of values of $K$ such that the sum of the compressed sequence is $\le S$. ### Constraints  $1 \le T \le 3$  $1 \le N \le 10^5$  $1 \le S \le 10^9$  $0 \le A_i \le 10^9$ for each valid $i$ ### Subtasks **Subtask #1 (10 points):** $1 \le N \le 100$ **Subtask #2 (30 points):** $1 \le N \le 1,000$ **Subtask #3 (60 points):** original constraints ### Example Input ``` 2 4 8 2 7 1 12 8 20 4 2 8 1 4 3 8 1 ``` ### Example Output ``` 2 4 ``` ### Explanation **Example case 1:** The possible values of $K$ are $0$ and $1$.Author:  likecs 
Editorial  https://discuss.codechef.com/problems/KCOMPRES 
Tags  aug18, binarysearch, likecs, likecs, medium, segmenttree 
Date Added:  20092017 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 