Created
August 20, 2019 01:07
-
-
Save luciocf/2318255635bfa48817b48a4dab6bc4d8 to your computer and use it in GitHub Desktop.
Comentário Noic OBI 2019 - Fase 1 - Programação Nível 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Comentário Noic OBI 2019 - Fase 1 - Programação Nível 1 | |
// Distância entre amigos | |
#include <bits/stdc++.h> | |
// valor "infinito" | |
const int inf = 1e9+10; | |
using namespace std; | |
int main(void) | |
{ | |
int n; | |
cin >> n; | |
// inicialmente, maior começa com um valor menor que | |
// o mínimo valor possível | |
int maior = -inf; | |
// resposta do problema | |
int ans = -inf; | |
for (int i = 1; i <= n; i++) | |
{ | |
// altura do i-ésimo prédio | |
int h; | |
cin >> h; | |
// atualizamos a resposta | |
ans = max(ans, h+i+maior); | |
// atualizamos o maior valor (H(i)-i) | |
maior = max(maior, h-i); | |
} | |
cout << ans << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment