#include <stdio.h>

int main() {
    int a,b,i,m,n,t=1;
    int x[10000];
    scanf("%d %d",&a,&b);
    for(i=0;i<a;i++)
    {
        scanf("%d",&x[i]);
    }
    while(t)
    {
        m=x[a]-x[0];
        if(m<b)
        {
            x[a]=m-1;
        }
        else if(m==b)
        {
            printf("%d",m);
            t=0;
        }
        else if(m>b)
        {
            x[0]=m+1;
        }
        else
        {
            t=0;
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: