Guest User

Untitled

a guest
Jan 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <iomanip>
  7. using namespace std;
  8. struct t
  9. {
  10.     int c;
  11.     bool b;
  12. };
  13.  
  14. bool foo(t a, t l)
  15. {
  16.     return(a.c < l.c);
  17. }
  18.  
  19. int main()
  20. {
  21.     //freopen("input.txt","r",stdin);
  22.     int n,k;
  23.     cin >>n >>k;
  24.  
  25.     vector <t> a(n);
  26.  
  27.     for (int i=0;i<n;++i)
  28.     {
  29.         cin >>a[i].c;
  30.         a[i].b=1;
  31.     }
  32.  
  33.     int q;
  34.     cin >>q;
  35.  
  36.     double mn=2000;
  37.     double mx=-1;
  38.     double e=0.00000001;
  39.     for (int i=0;i<q;++i)
  40.     {
  41.         int s=0;
  42.         for (int j=0;j<(n/k);++j)
  43.         {
  44.             int h;
  45.             cin >>h;
  46.             a[h-1].b=0;
  47.             s+=a[h-1].c;
  48.         }
  49.         if (mn - double (double (s)/(n/k)) > e )
  50.             mn= double (double (s)/(n/k));
  51.         if (mx - double (double (s)/(n/k)) < e )
  52.             mx= double (double (s)/(n/k));
  53.     }
  54.  
  55.     sort(a.begin(),a.end(),foo);
  56.  
  57.     if (k!=q)
  58.     {
  59.  
  60.         int i=0;
  61.         int j=0;
  62.         bool f=true;
  63.         int s=0;
  64.         while (f && j<n)
  65.         {
  66.        
  67.  
  68.             if (a[j].b==1)
  69.             {
  70.                 s+=a[j].c;
  71.                 ++i;
  72.             }
  73.             if (i>=(n/k)) f=false;
  74.             ++j;
  75.  
  76.         }
  77.         if (f==false) if (mn - double (double (s)/(n/k)) > e )
  78.             mn= double (double (s)/(n/k));
  79.    
  80.    
  81.  
  82.         i=0;
  83.         j=n-1;
  84.         f=true;
  85.         s=0;
  86.         while (f && j>=0)
  87.         {
  88.             if (a[j].b==1)
  89.             {
  90.                 s+=a[j].c;
  91.                 ++i;
  92.             }
  93.             if (i>=(n/k)) f=false;
  94.             --j;
  95.         }
  96.         if (f==false) if (mx - double (double (s)/(n/k)) < e )
  97.             mx= double (double (s)/(n/k));
  98.     }
  99.    
  100.     cout << setprecision (10) <<mn <<' ' <<mx <<endl;
  101.  
  102.  
  103.  
  104. }
Add Comment
Please, Sign In to add comment