StoneHaos

312

Nov 2nd, 2019
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //312
  2. #include <cstdio>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main(void) {
  7.     FILE* fin = fopen("input.txt", "r");
  8.     FILE* fout = fopen("output.txt", "w");
  9.  
  10.     int n, p = 0, last_elem, current_elem;
  11.     fscanf(fin, "%d", &n);
  12.     fscanf(fin, "%d", &last_elem);
  13.     p = 2 + 2 * last_elem;
  14.     for (int i = 1; i < n; ++ i) {
  15.         fscanf(fin, "%d", &current_elem);
  16.         p += (2 + 2 * current_elem) - 2 * min(last_elem, current_elem);
  17.         last_elem = current_elem;
  18.     }
  19.     fclose(fin);
  20.     fprintf(fout, "%d\n", p);
  21.     fclose(fout);
  22.     return 0;
  23. }
RAW Paste Data