Advertisement
Josif_tepe

Untitled

Mar 5th, 2025
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.    
  10.     int dali_e_prv_element = -1;
  11.     int prethoden_broj = -1;
  12.     int najmal;
  13.     long long res =0 ;
  14.     for(int i = 0; i < n; i++) {
  15.         int x;
  16.         cin >> x;
  17.        
  18.         if(dali_e_prv_element == -1) {
  19.             dali_e_prv_element = 1;
  20.             prethoden_broj = x;
  21.             najmal = x;
  22.         }
  23.         else {
  24.             if(prethoden_broj + 1 != x) {
  25.                 res += najmal;
  26.                 najmal = x;
  27.             }
  28.             prethoden_broj = x;
  29.         }
  30.        
  31.     }
  32.     cout << res + najmal << endl;
  33.    
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement