Editorial for Кръг


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by:

Тестовете можете да видите тук.

Примерно решение на C++:

#include <stdio.h>
#define MAXN 1000001
int a[MAXN][2];
int main()
{
    int N,K;
    int i,j,t,u,v;

    scanf("%d %d",&N,&K);
    for(i=1;i<=N;i++) 
    {scanf("%d",&a[i][0]);a[i][1]=i+1;}
    a[N][1]=1;t=1;
    for(i=1;i<=N-1;i++)
    {
       for(j=2;j<K;j++) t=a[t][1];
       u=a[t][1]; //u - adres na iztriania

       K=a[u][0]; //K-to na iztrivania
       a[t][1]=a[u][1];
       t=a[u][1];                   
    }
    printf("%d\n",t);   
}

Comments

There are no comments at the moment.