Positive Array Codechef contest Problem Solution
A 1
-indexed array is called positive if every element of the array is greater than or equal to the index on which it lies. Formally, an array
For example, the arrays
You are given an array
Find the minimum number of positive arrays that the elements of the array
Please see the sample cases below for more clarity.
Input Format
- The first line of input will contain a single integer
T , denoting the number of test cases. - Each test case consists of two lines of input.
- The first line of each test case contains an integer
N — the number of elements in the arrayA - The next line contains
N space-separated integersA1,A2,…,AN — the elements of arrayA
- The first line of each test case contains an integer
Output Format
For each test case, output on a new line the minimum number of positive arrays that the elements of the array
Constraints
1 ≤ T ≤ 10^4 1 ≤ N ≤ 10^5 1 ≤ A i≤ N - The sum of
N over all test cases won’t exceed2⋅105
Sample Input 1
5
3
2 3 3
4
3 1 1 2
3
1 1 1
5
1 2 2 4 5
6
3 2 1 2 2 1
Sample Output 1
1
2
3
2
3
Explanation
Test case
Test case
Test case
Test case
Test case
#include
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL);
#define int long long
using namespace std;
void solve(){
int n;
cin>>n;
int a[n];
multiset s;
for (int i=0;i>a[i];
s.insert(a[i]);
}
int res = 1, ptr = 1;
while (s.size()>0){
auto i = s.lower_bound(ptr);
if (i!=s.end()){
// cout<>t;
while(t--){
solve();
}
}
0 Comments