Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- int dali_e_prv_element = -1;
- int prethoden_broj = -1;
- int najmal;
- long long res =0 ;
- for(int i = 0; i < n; i++) {
- int x;
- cin >> x;
- if(dali_e_prv_element == -1) {
- dali_e_prv_element = 1;
- prethoden_broj = x;
- najmal = x;
- }
- else {
- if(prethoden_broj + 1 != x) {
- res += najmal;
- najmal = x;
- }
- prethoden_broj = x;
- }
- }
- cout << res + najmal << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement