fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define watch2(x , y) cerr<<(#x)<<" = "<<(x)<<" "<<(#y)<<" = "<<(y)<<"\n"
  4. int SD(){int x; scanf("%d" , &x); return x;}
  5. const int AKA = 1e6 + 6 , OO = 1e9;
  6. int a[AKA];
  7. int main()
  8. {
  9. int t = SD();
  10. while(t--)
  11. {
  12. int n = SD() , cnt = 0 , mnV = OO , f = 0;
  13. for(int i = 0 ; i < n ; ++i)
  14. a[i] = SD() , cnt += (a[i] == -1) , a[i] != -1 ? mnV = min(mnV , a[i]) : 0;
  15. for(int i = 0 ; i < n - 1 ; ++i)
  16. if(a[i] != -1 && a[i + 1] != -1)
  17. f = 1;
  18. if(cnt == n)
  19. puts("0 42");
  20. else if(cnt == n - 1)
  21. printf("0 %d\n" , mnV);
  22. else if(f == 1)
  23. {
  24. int m = -1 , k = -1;
  25. for(int i = 0 ; i < n - 1 ; ++i)
  26. if(a[i] != -1 && a[i + 1] != -1)
  27. m = max(m , abs(a[i] - a[i + 1]));
  28. vector<int> v;
  29. for(int i = 0 ; i < n ; ++i)
  30. if(a[i] == -1)
  31. v.push_back(m);
  32. else
  33. v.push_back(a[i]);
  34. for(int i = 0 ; i < v.size() - 1 ; ++i)
  35. k = max(k , abs(v[i] - v[i + 1]));
  36. printf("%d %d\n" , m , k);
  37. }
  38. else
  39. {
  40. vector<int> v;
  41. for(int i = 0 ; i < n ; ++i)
  42. if(a[i] != -1)
  43. v.push_back(a[i]);
  44. int m = -1 , k = -1;
  45. for(int i = 0 ; i < v.size() - 1 ; ++i)
  46. m = max(m , (int)( (v[i] + v[i + 1]) / 2.00));
  47. vector<int> vv;
  48. for(int i = 0 ; i < n ; ++i)
  49. if(a[i] == -1)
  50. vv.push_back(m);
  51. else
  52. vv.push_back(a[i]);
  53. for(int i = 0 ; i < vv.size() - 1 ; ++i)
  54. k = max(k , abs(vv[i] - vv[i + 1]));
  55. printf("%d %d\n" , k , m);
  56. }
  57. }
  58. }
  59.  
Success #stdin #stdout 0s 4344KB
stdin
1
6
5 1 2 3 4 -1
stdout
4 4