Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include<fstream>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7. int readInt()
  8. {
  9. int res = 0;
  10. char ch = 0;
  11. while(ch < '0') ch = getchar_unlocked();
  12. for(; ch >= '0'; ch = getchar_unlocked()) res = res * 10 + ch - '0';
  13. return res;
  14.  
  15. }
  16.  
  17. void writeInt(int v)
  18. {
  19. //cout << v;
  20.  
  21. char buf[14];
  22. int p = 0;
  23. if(v == 0) buf[p++] = 0;
  24. for(; v; v /= 10) buf[p++] = v % 10;
  25. while(p--) putchar_unlocked(buf[p] + '0');
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.  
  32. freopen("input.txt", "r", stdin);
  33. freopen("output.txt", "w", stdout);
  34.  
  35. int min, max, n;
  36. n = readInt();
  37.  
  38. int act[n];
  39.  
  40. act[0] = readInt();
  41. act[1] = readInt();
  42. min = 2 * act[0] - act[1];
  43. max = act[0];
  44.  
  45. int combinazioniMinime = 1500000000;
  46. int temp;
  47. for(int i = 1; i <= n; i++)
  48. {
  49. if(i != 1 && i != n)
  50. act[i] = readInt();
  51. // trovo min e max
  52. temp = min;
  53. min = 2*act[i-1] - max;
  54. max = 2*act[i-1] - temp;
  55.  
  56. if(max > act[i] && i!=n)
  57. max = act[i];
  58.  
  59.  
  60. temp = max - min + 1;
  61. if(max - min + 1 < combinazioniMinime)
  62. combinazioniMinime = temp;
  63. }
  64.  
  65.  
  66. writeInt(combinazioniMinime);
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement