View Code of Problem 17

#include<iostream>
#include <climits>
#include <algorithm>
using namespace std;
int main()
{
    int n,m,i,j,max_x=0;
    int *temp;
    cin>>n>>m;
    temp=new int[n*m];
    for(i=0;i<(n*m);i++)
        cin>>temp[i];
    sort(temp,temp+(n*m));
    int loca=0;
    while(loca<(n*m-1)){
        for(i=loca+1;i<(n*m);i++){
            if(temp[i]-temp[i-1]>=2){
                j=temp[i-1]-temp[loca];
                max_x<j?max_x=j:max_x;
                j=0;
                break;
            }
            else{
                if(temp[i]-temp[i-1]==1)
                    j++;
            }
        }
        max_x<j?max_x=j:max_x;
        j=0;
        loca=i;
    }
    cout<<max_x<<endl;
    return 0;
}

Double click to view unformatted code.


Back to problem 17