April LunchTime SHUFFLE getting partial but idea seems to pass all test cases!

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
ll t;
cin>>t;
while(t–)
{
ll n,k;
cin>>n>>k;
ll a[n+1];
a[0]=INT_MIN;
priority_queue <ll, vector, greater> PQ;
multimap<ll,ll>mp;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
PQ.push(a[i]);
}

    ll pos=1;
    while(!PQ.empty())
    {
        ll x = PQ.top();
        PQ.pop();
        mp.insert({x,pos});
        ++pos;
    }

/*
for(auto it=mp.begin();it!=mp.end();++it)
{
cout<first<<"->"<second<<endl;
}
*/
bool ans=true;
for(ll i=1;i<=n;i++)
{
auto itr = mp.find(a[i]);
ll x = i;
ll y = itr->second;
mp.erase(itr);
//cout<<x<<" "<<y<<endl;
if(x != y)
{
if( ((abs(x-y)%k)) != 0 )
{
ans=false;
break;
}
else continue;
}
else continue;
}
if(ans)
cout<<“yes\n”;
else cout<<“no\n”;
//cout<<mp.size()<<endl;
}
return 0;
}

You will have problem when there are duplicate numbers

1 Like

@sebastian Can you explain through example ,please?
For example take this example - [8,3,5,7,8,7,3] or [2,2,2,2]

btw has this code compiled?
You have only written “while(t-)”

Yeah Bro Code is getting Compiled and executed , the only problem is that I want to understand why and how ,through examples, this doesn’t work for array elements with duplicates ??