Advertisement
Serega

Before Exam

Oct 16th, 2011
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6. int n, k, a[100], q, ans_mx = -1, ans_mn = 1E9, nmb;
  7. bool used[100];
  8. vector<int> rem;
  9. int main()
  10. {
  11.     cin >> n >> k; nmb = n / k;
  12.     for (int i = 0; i < n; ++i) cin >> a[i];
  13.     int f = 0;
  14.     cin >> q;
  15.     for (int i = 0; i < q; ++i)
  16.     {
  17.         bool yes = false;
  18.         int cur, sum = 0;
  19.         for (int j = 0; j < nmb; ++j)
  20.         {
  21.             cin >> cur; --cur;
  22.             if (!used[cur] && !yes)
  23.             {
  24.                 yes = true;
  25.                 ++f;
  26.             }
  27.             used[cur] = true;
  28.             sum += a[cur];
  29.         }
  30.         ans_mx = max(ans_mx, sum);
  31.         ans_mn = min(ans_mn, sum);
  32.     }
  33.     for (int i = 0; i < n; ++i)
  34.         if (!used[i]) rem.push_back(a[i]);
  35.     sort(rem.begin(), rem.end());
  36.     if (rem.size() >= nmb && f < k)
  37.     {
  38.         int sum1 = 0,sum2 = 0;
  39.         for (int i = 0; i < nmb; ++i) { sum1 += rem[i]; sum2 += rem[rem.size() - 1 - i]; }
  40.         ans_mx = max(ans_mx, sum2);
  41.         ans_mn = min(ans_mn, sum1);
  42.     }
  43.     printf("%.10lf %.10lf", ans_mn * 1.0 / nmb, ans_mx * 1.0 / nmb);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement