Skip to content

Instantly share code, notes, and snippets.

@sofhiasouza
Created April 24, 2019 03:06
Show Gist options
  • Save sofhiasouza/542ab62cb4bad0767be3c3f4ff71e7a2 to your computer and use it in GitHub Desktop.
Save sofhiasouza/542ab62cb4bad0767be3c3f4ff71e7a2 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define inf 1000000000
using namespace std;
int main()
{
int n, k, vet[10010], dif[10010];
cin >> n >> k;
for(int i = 1 ; i <= n ; i++)
{
cin >> vet[i];
if(i != 1) dif[i-1] = abs(vet[i]-vet[i-1]); //guardo o valor das diferenças no meu vetor dif
}
int resp = inf;
for(int i = 1 ; i <= k ; i++)
{
int maior = 0;
for(int j = i ; j < (n-k+i-1) ; j++) maior = max(maior, dif[j]); //percorro todos os intervalos possiveis e pego o maior de cada um
resp = min(maior, resp); //pego o menor dos maiores
}
cout << resp << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment