Ross generates Data
below given code is for akvod05 spoj or ross generates data spoj.
AKV sir.
#include <stdio.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int k,n;
scanf("%d%d",&n,&k);
int result[k+9],a[k+9],check[100009]={0};
int i,j,l=0,loop=n%(k+1);
//cout<<loop<<endl;
for(i=0;i<k;i++)
{
scanf("%d",&a[i]);
if(a[i]<=k)
check[a[i]]++;
}
for(j=0;j<=k;j++)
if(check[j]==0)
{
result[l++]=j;
check[j++]++;
break;
}
for(i=0;i<=loop;i++)
{
if(a[i]<=k)
{
//cout<<i<<" here"<<endl;
check[a[i]]--;
if(a[i]<=j && check[a[i]]==0)
{
//cout<<"here"<<a[i]<<" "<<i<<" "<<l<<endl;
result[l++]=a[i];
check[a[i]]++;
}
else
for(;j<=k;j++)
{
if(check[j]==0)
{
result[l++]=j;
check[j++]++;
break;
}
}
}
else
for(;j<=k;j++)
{
if(check[j]==0)
{
result[l++]=j;
check[j++]++;
break;
}
}
}
printf("%d\n",result[loop]);
}
return 0;
}
No comments:
Post a Comment
Your comment is valuable to us