Advertisement
Josif_tepe

Untitled

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