Advertisement
Josif_tepe

Untitled

Mar 1st, 2025
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int a[n];
  10.     for(int i = 0; i < n; i++) {
  11.         cin >> a[i];
  12.     }
  13.     int res = 0;
  14.     for(int i = 0; i < n; i++) {
  15.         int najmal_broj = a[i];
  16.         int prv = a[i];
  17.         int j = i + 1;
  18.        
  19.         while(j < n and prv + 1 == a[j]) {
  20.             j++;
  21.             prv++;
  22.         }
  23.         res += najmal_broj;
  24.         i = j - 1;
  25.        
  26.     }
  27.     cout << res << endl;
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement