fork(4) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <iomanip>
  14. #define dibs reserve
  15. #define OVER9000 1234567890
  16. #define patkan 9
  17. #define tisic 47
  18. #define soclose 1e-9
  19. #define pi 3.1415926535898
  20. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  21. #define chocolate win
  22. #define ff first
  23. #define ss second
  24. #define abs(x) ((x < 0)?-(x):(x))
  25. #define uint unsigned int
  26. #include <time.h>
  27. // mylittlepony
  28. using namespace std;
  29.  
  30. int N;
  31. vector<double> S;
  32.  
  33. bool check(double k) {
  34. double Q =S[N]-N*k, m =S[1]-k;
  35. for(int j =2; j < N; j++) {
  36. if(Q-(S[j]-j*k)+m < soclose) return true;
  37. m =min(m,S[j]-j*k);}
  38. return false;}
  39.  
  40. int main() {
  41. freopen("sabotage.in","r",stdin);
  42. freopen("sabotage.out","w",stdout);
  43. scanf(" %d",&N);
  44. vector<int> A(N);
  45. for(int i =0; i < N; i++) scanf(" %d",&A[i]);
  46. S.resize(N+1,0);
  47. for(int i =0; i < N; i++) S[i+1] =S[i]+A[i];
  48.  
  49. double ansA =0, ansB =1e+20;
  50. while(ansB-ansA > soclose) {
  51. double k =(ansB+ansA)/2;
  52. if(check(k)) ansB =k;
  53. else ansA =k;}
  54.  
  55. printf("%.3f\n",ansB);
  56. return 0;}
  57.  
  58. // look at my code
  59. // my code is amazing
  60.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Standard output is empty