View Code of Problem 17

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>

int a[1000005];

int compare (const void * a, const void * b)
{
    return ( *(int*)a - *(int*)b );
}

int main()
{
    int n, m;
    while (scanf("%d%d", &n, &m) != EOF) {
        for (int i = 0; i < n * m; i++) {
            scanf("%d", &a[i]);
        }
        
        qsort(a, n * m, sizeof(int), compare);
        int i = 1;
        int mxc = 0;
        while (i < n * m) {
            int count = 0;
            while (a[i] == a[i - 1] + 1 && i < n * m) {
                i++;
                count++;
            }
            if (count > mxc) {
                mxc = count;
            }
            i++;
        }
        
        printf("%d\n", mxc);
    }
}

Double click to view unformatted code.


Back to problem 17