Advertisement
vitormartinotti

OBI2022_f2pj_caminho

Aug 9th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int N;
  7.     scanf("%d", &N);
  8.  
  9.     int postes[N];
  10.     for(int i = 0; i < N; i++){
  11.         scanf("%d", &postes[i]);
  12.     }
  13.  
  14.     //Checa a soma do valor de um poste com seu próximo, até o penúltimo poste
  15.     int trecho_escuro = 0, sequencia = 0;
  16.     for(int i = 0; i < N - 1; i++){ //Atenção na parte "i < N-1"
  17.         if(postes[i] + postes[i+1] < 1000){
  18.             trecho_escuro++;
  19.         }
  20.         else{
  21.             if(trecho_escuro > sequencia) sequencia = trecho_escuro;
  22.             trecho_escuro = 0;
  23.         }
  24.     }
  25.  
  26.     //Checa a soma do valor do último poste com o primeiro (pois  os postes estão dispostos formando um círculo)
  27.  
  28.     if(postes[N - 1] + postes[0] < 1000){
  29.             trecho_escuro++;
  30.     }
  31.  
  32.     if(trecho_escuro > sequencia) sequencia = trecho_escuro;
  33.  
  34.     printf("%d", sequencia);
  35.  
  36.     return 0;
  37. }
  38.  
Tags: OBI2022
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement