Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //312
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- int main(void) {
- FILE* fin = fopen("input.txt", "r");
- FILE* fout = fopen("output.txt", "w");
- int n, p = 0, last_elem, current_elem;
- fscanf(fin, "%d", &n);
- fscanf(fin, "%d", &last_elem);
- p = 2 + 2 * last_elem;
- for (int i = 1; i < n; ++ i) {
- fscanf(fin, "%d", ¤t_elem);
- p += (2 + 2 * current_elem) - 2 * min(last_elem, current_elem);
- last_elem = current_elem;
- }
- fclose(fin);
- fprintf(fout, "%d\n", p);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement