#include<bits/stdc++.h>
#define INF 1e9+7
#define endl "\n"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define fileopen freopen("input.txt", "rt", stdin);
#define fileclose freopen("output.txt", "wt", stdout);
#define Fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hash visited.max_load_factor(0.25);visited.reserve(512)
using namespace std;
int main()
{
Fio;
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
vll v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
sort(all(v));
ll cnt=0;
ll grp_cnt=0;
for(int i=0;i<n;i++)
{
if(grp_cnt==0)
{
grp_cnt=i;
}
if(i-grp_cnt+1 >= v[i])
{
cnt++;
grp_cnt=0;
}
}
cout<<cnt<<endl;
}
}
#include<bits/stdc++.h>
#define INF 1e9+7
#define endl "\n"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define fileopen freopen("input.txt", "rt", stdin);
#define fileclose freopen("output.txt", "wt", stdout);
#define Fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hash visited.max_load_factor(0.25);visited.reserve(512)
using namespace std;
int main()
{
Fio;
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
vll v(n+1);
for(int i=1;i<=n;i++)
{
cin>>v[i];
}
sort(all(v));
ll cnt=0;
ll grp_cnt=0;
for(int i=1;i<=n;i++)
{
if(grp_cnt==0)
{
grp_cnt=i;
}
if(i-grp_cnt+1 >= v[i])
{
cnt++;
grp_cnt=0;
}
}
cout<<cnt<<endl;
}
}
For the input:
3
2 3 3
Correct Output(Second code):
1
Wrong Output(first code):
0
In the second code, i am storing the values in index 1 to N
In first code, i am storing the values in index 0 to N-1
But i am getting a different output. Why is this happening?