ACM (UVa) : 957


// http://online-judge.uva.es/p/v9/957.html

#include <stdio.h>

int main ()
{
    int y;

    while ( scanf ("%d", &y) != EOF ) {

        y--;

        int p;
        scanf ("%d", &p);

        int a [p];
        for ( int i = 0; i < p; i++ )
        scanf ("%d", & a [i]);

        int count = 0;
        int j;
        int first;
        int last;
        int max = 0;

        for ( int i = 0; i < p; i++ ) {
            j = i;
            count = 0;
            while ( a [j] <= a [i] + y ) {
                j++;
                count++;
            }

            if ( count > max ) {
                max = count;
                first = a[i];
                last = a[j - 1];
            }
        }

        printf ("%d %d %d\n", max, first, last);
    }

    return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s