Poj Solution 2189

http://poj.org/problem?id=2189

#include <stdio.h>
#include <algorithm>
#include <memory.h>
using namespace std;

int n,p,c;
int s[1001];

int main()
{
    int i, j, k;
    scanf( "%d %d %d", &n, &p, &c );

    memset( s, 0, sizeof( s ) );

    for( i=0; i<n; i++ )
    {
        scanf( "%d", &j );
        s[j]++;
    }
    s[0] = 0;

    for( i=1; i<p; i++ )
    s[i] += s[i-1];

    k = -1;
    for( i=1; i<p; i++ )
    {
        j = lower_bound( s, s+i, s[i] - c ) - s;
        if( i-j > k )k = i - j;
    }

    printf( "%dn", k );

    return 0;
}

    


											
This entry was posted in poj. Bookmark the permalink.