You are given an integer array $$$a$$$ containing $$$n$$$ elements.
You can do the following operation on array $$$a$$$ :
What are the minimum number of elements in $$$a$$$ after performing the above operation for at most $$$k$$$ times.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of test case contains two integers $$$n,k$$$ ($$$1 \le n,k \le 10^3$$$) — the length of the array $$$a$$$ and the number of operations performed.
The second line of each test case contains $$$n$$$ space separated integers $$$a_{i}$$$ ($$$1 \le a_{i} \le 10^3$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^3$$$.
For each test case, print single integer — minimum number of elements in $$$a$$$ after performing the operation for at most $$$k$$$ times.
81 111 352 54 63 11 2 35 43 5 7 9 105 31 2 3 4 57 20190 910 999 189 672 111 67310 21000 1000 1000 1000 1000 1000 1000 1000 1000 1000
1 1 1 2 1 2 1 8
In the $$$5^{th}$$$ test case,
Initially, $$$a$$$ is $$$(3, 5, 7, 9, 10)$$$.
Hence, total $$$1$$$ element is there in $$$a$$$ after performing $$$4$$$ operations.
You are given an integer array $$$a$$$ containing $$$n$$$ elements.
A pair $$$(l, r) (1 \le l \le r \le n)$$$ is called Normal pair, if $$$^\dagger$$$ $$$MEX(a_{l},a_{l+1},....,a_{r-1},a_{r})$$$ has maximum value among all other pairs.
Out of all possible Normal pairs, find a pair $$$(l, r)$$$ which has a minimum value of $$$(r-l+1)$$$.
$$$^\dagger$$$ $$$MEX(b)$$$ is defined as the smallest non-negative integer which is not present in $$$b$$$. For example $$$MEX(1, 0, 3) = 2$$$, $$$MEX(2, 5, 3) = 0$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$.
The second line of each test case contains $$$n$$$ space separated integers $$$a_{i}$$$ ($$$0 \le a_{i} \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
For each test case, print a single integer — the minimum value of $$$(r-l+1)$$$, such that $$$MEX(a_{l},a_{l+1},....,a_{r-1},a_{r})$$$ has maximum value.
543 3 0 151 1 2 0 065 0 3 5 1 1610 11 23 22 9 387 4 2 4 0 7 2 1
2 3 4 1 4
In the $$$2^{nd}$$$ test case,
The possible Normal pairs are $$$(1, 4), (1, 5), (2, 4), (2, 5)$$$
So, for $$$l = 2, r = 4$$$, $$$MEX(1,2,0) = 3$$$ which is maximum.
Hence the smallest value of $$$(r-l+1) = 3$$$.
You are given an integer array $$$a(a_{1},a_{2},....,a_{n})$$$containing $$$n$$$ elements, it is guaranteed that $$$n$$$ is even.
Let's define some definitions:
You are allowed to do the following operation on $$$a$$$:
Let the array $$$b$$$ be the resultant array $$$a$$$ after performing above operation any times(possibly zero).
Output any $$$b$$$ which has minimum $$$f(b)$$$.
$$$^\dagger$$$ Range of the set $$$S$$$ is defined as the difference between the maximum element and minimum element in $$$S$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of test case contains a single integers $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$, it is guaranteed thar $$$n$$$ is even.
The second line of each test case contains $$$n$$$ space separated integers $$$a_{i}$$$ ($$$1 \le a_{i} \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
For each test case, print $$$n$$$ space seperated integers — the array $$$b$$$ which has minimum $$$f(b)$$$.
521 243 9 7 542 4 4 463 2 1 6 5 461000 1000 1000 1000 1000 1000
2 1 9 5 7 3 2 4 4 4 3 5 1 6 2 4 1000 1000 1000 1000 1000 1000
In the $$$4^{th}$$$ test case,
Let $$$b = (3,5,1,6,2,4)$$$
So, $$$S_{1}(b) = (3,1,2)$$$ and $$$S_{2}(b) = (5,6,4)$$$
so, $$$R(S_{1}(b)) = (3 - 1) = 2$$$ and $$$R(S_{2}(b)) = (6 - 4) = 2$$$
Hence, $$$f(b) = 2 * 2 = 4$$$.
It is shown that, there is no other $$$b$$$ where $$$f(b)$$$ is smaller than $$$4$$$.
You are given a binary string$$$^\dagger$$$ $$$S$$$ of length $$$n$$$.
For a given non-negative integer $$$m$$$ you can choose any binary string $$$P$$$ of length $$$n$$$ which contains $$$m$$$ $$$1's$$$ and $$$(n-m)$$$ $$$0's$$$.
Let the binary string $$$T = S \oplus P$$$, where $$$\oplus$$$ denotes Bitwise XOR
What are the maximum number of contiguous substrings of length $$$2$$$ in $$$T$$$ which are equal to $$$'11'$$$.
Solve the above problem for every $$$m(0 \le m \le n)$$$ .
$$$^\dagger$$$ A binary string is a string which only contains $$$0's$$$ and $$$1's$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the binary string.
The second line of each testcase contains a binary string $$$S$$$ of length $$$n$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^6$$$
For each test case, print $$$n+1$$$ space seperated integers — the required answer for every $$$m(0 \le m \le n)$$$.
43010301140011511100
0 1 2 0 1 2 1 0 1 2 3 2 1 2 3 4 3 2 1
In the $$$1^{st}$$$ test case,
You are given two integer arrays $$$a(a_{0},a_{1},....,a_{n-1})$$$ containing $$$n$$$ elements, $$$b(b_{0},b_{1},....,b_{n-1})$$$ containing $$$n$$$ elements and an integer $$$k$$$.
You are allowed to do the following popular segment tree Operation on array $$$a$$$.
Find the minimum number of Operations required to change $$$a$$$ to $$$b$$$ or report if it is impossible to do.
Note that, $$$x\%y$$$ is the remainder when $$$y$$$ divides $$$x$$$. i.e., $$$(10\%4) = 2$$$, $$$(-5\%4) = 3$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The first line of test case contains two integers $$$n,k$$$ ($$$1 \le n \le 2 \cdot 10^6$$$, $$$0 \le k \le ⌊\frac{n-1}{2}⌋$$$) — the length of the given arrays and an integer.
The second line of each test case contains $$$n$$$ space separated integers $$$a_{i}$$$ ($$$1 \le a_{i} \le 10^{12}$$$).
The third line of each test case contains $$$n$$$ space separated integers $$$b_{i}$$$ ($$$1 \le b_{i} \le 10^{12}$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^6$$$.
For each test case, print a single integer — the minimum number of Operations required to change $$$a$$$ to $$$b$$$ or $$$"-1"$$$(without quotes) if it is impossible to change.
34 11 4 3 217 14 25 26 21 1 1 1 1 11 49 5 29 9 135 21 2 3 9 112 4 6 18 22
4 5 -1
In the first test case,
Hence, the total operations required are $$$4$$$.
This is the easy version of the problem. The changes in this version are highlighted in bold characters.
Yugandhar have an undirected graph containing $$$n$$$ nodes numbered $$$1,2,....,n$$$. Initially there are $$$0$$$ edges i.e., there are total $$$n$$$ connected components in the graph. He has a freedom to add exactly $$$k$$$ undirected edges in this graph, each edge can be added between $$$u$$$ and $$$v$$$ if and only if $$$v$$$ = $$$u+1$$$. Note that he can add multiple edges between two nodes.
After giving this graph to wuhudsm, he will observe the following $$$m$$$ requirements and reward him coins :
So Please tell him the optimal way to select these $$$k$$$ edges to get maximum number of coins.
Aditionally, help him for $$$q$$$ queries.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of test case contains three integers $$$n,m,q$$$ ($$$2 \le n \le \bf{2 \cdot 10^3}$$$, $$$1 \le m \le \bf{2 \cdot 10^3}$$$, $$$1 \le q \le 10^6$$$) — the number of nodes in graph, the number of requirements and the number of queries.
Next $$$m$$$ lines of each test case contains three space separated integers $$$x_{i}, y_{i}, c_{i}$$$ ($$$1 \le x_{i}, y_{i} \le n$$$, $$$x_{i} ≠ y_{i}$$$, $$$1 \le c_{i} \le 10^9$$$).
Next $$$q$$$ lines of each test case contains a single integer $$$k_{i}$$$ ($$$1 \le k_{i} \le 10^9$$$) — the total number of edges needed to add in graph.
It is guaranteed that the sum of $$$n$$$ and sum of $$$m$$$ over all test cases doesn't exceed $$$\bf{2 \cdot 10^3}$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases doesn't exceed $$$10^6$$$.
For each test case print $$$q$$$ integers — the maximum number of coins he can get if he choose exactly $$$k_{i}$$$ edges optimally.
34 2 23 4 31 3 2135 3 33 4 23 1 52 5 102166 5 41 2 13 2 13 4 15 4 26 5 134810
3 5 5 2 17 4 5 6 6
This is the hard version of the problem. The changes in this version are highlighted in bold characters.
Yugandhar have an undirected graph containing $$$n$$$ nodes numbered $$$1,2,....,n$$$. Initially there are $$$0$$$ edges i.e., there are total $$$n$$$ connected components in the graph. He has a freedom to add exactly $$$k$$$ undirected edges in this graph, each edge can be added between $$$u$$$ and $$$v$$$ if and only if $$$v$$$ = $$$u+1$$$. Note that he can add multiple edges between two nodes.
After giving this graph to wuhudsm, he will observe the following $$$m$$$ requirements and reward him coins :
So Please tell him the optimal way to select these $$$k$$$ edges to get maximum number of coins.
Aditionally, help him for $$$q$$$ queries.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of test case contains three integers $$$n,m,q$$$ ($$$2 \le n \le \bf{10^4}$$$, $$$1 \le m \le \bf{10^4}$$$, $$$1 \le q \le 10^6$$$) — the number of nodes in graph, the number of requirements and the number of queries.
Next $$$m$$$ lines of each test case contains three space separated integers $$$x_{i}, y_{i}, c_{i}$$$ ($$$1 \le x_{i}, y_{i} \le n$$$, $$$x_{i} ≠ y_{i}$$$, $$$1 \le c_{i} \le 10^9$$$).
Next $$$q$$$ lines of each test case contains a single integer $$$k_{i}$$$ ($$$1 \le k_{i} \le 10^9$$$) — the total number of edges needed to add in graph.
It is guaranteed that the sum of $$$n$$$ and sum of $$$m$$$ over all test cases doesn't exceed $$$\bf{10^4}$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases doesn't exceed $$$10^6$$$.
For each test case print $$$q$$$ integers — the maximum number of coins he can get if he choose exactly $$$k_{i}$$$ edges optimally.
34 2 23 4 31 3 2135 3 33 4 23 1 52 5 102166 5 41 2 13 2 13 4 15 4 26 5 134810
3 5 5 2 17 4 5 6 6