Advertisement
Guest User

Codefroces62B

a guest
Mar 19th, 2011
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<iomanip>
  6. using namespace std;
  7.  
  8. vector<int> en;
  9. int n, pre, nex, a=1, b=1, k, tem;
  10. double pr, t, maxi, mini;
  11. bool qw;
  12.  
  13. void init()
  14. {
  15.     sort(en.begin(), en.end());
  16.     a=1; b=1; nex=1; pre=n-2; maxi=en[n-1]; mini=en[0]; pr=1-((double)k)/(100.0);
  17. };
  18.  
  19. int main()
  20. {
  21.     cout.precision(10);
  22.     cin>>n>>k;
  23.     for(int i=1;i<=n;i++)
  24.     {
  25.         cin>>tem;
  26.         en.push_back(tem);
  27.     };
  28.     init();
  29.     while(pre>=nex)
  30.     {
  31.         t=(maxi-(double)en[pre])*((double)a);
  32.         qw=true;
  33.         if(mini+(t/b)*pr>(double)en[nex])
  34.         {
  35.             t=(b*((double)en[nex]-mini))/pr;
  36.             qw=false;
  37.         };
  38.         maxi=maxi-t/((double)a);
  39.         mini=mini+t/((double)b)*pr;
  40.         if(qw)
  41.         {
  42.             a++;
  43.             pre--;
  44.         }
  45.         else
  46.         {
  47.             b++;
  48.             nex++;
  49.         };
  50.     };
  51.     if(mini==maxi)
  52.     {
  53.         cout<<mini;
  54.         cin>>n;
  55.         return 0;
  56.     };
  57.     t=(maxi-mini)/((pr)/((double)b)+(1.0)/((double)a));
  58.     cout<<maxi-t/((double)a)<<endl;
  59.     cin>>n;
  60. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement