Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include<fstream>
- #include <cstdio>
- using namespace std;
- int readInt()
- {
- int res = 0;
- char ch = 0;
- while(ch < '0') ch = getchar_unlocked();
- for(; ch >= '0'; ch = getchar_unlocked()) res = res * 10 + ch - '0';
- return res;
- }
- void writeInt(int v)
- {
- //cout << v;
- char buf[14];
- int p = 0;
- if(v == 0) buf[p++] = 0;
- for(; v; v /= 10) buf[p++] = v % 10;
- while(p--) putchar_unlocked(buf[p] + '0');
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int min, max, n;
- n = readInt();
- int act[n];
- act[0] = readInt();
- act[1] = readInt();
- min = 2 * act[0] - act[1];
- max = act[0];
- int combinazioniMinime = 1500000000;
- int temp;
- for(int i = 1; i <= n; i++)
- {
- if(i != 1 && i != n)
- act[i] = readInt();
- // trovo min e max
- temp = min;
- min = 2*act[i-1] - max;
- max = 2*act[i-1] - temp;
- if(max > act[i] && i!=n)
- max = act[i];
- temp = max - min + 1;
- if(max - min + 1 < combinazioniMinime)
- combinazioniMinime = temp;
- }
- writeInt(combinazioniMinime);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement