Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int n, k, a[100], q, ans_mx = -1, ans_mn = 1E9, nmb;
- bool used[100];
- vector<int> rem;
- int main()
- {
- cin >> n >> k; nmb = n / k;
- for (int i = 0; i < n; ++i) cin >> a[i];
- int f = 0;
- cin >> q;
- for (int i = 0; i < q; ++i)
- {
- bool yes = false;
- int cur, sum = 0;
- for (int j = 0; j < nmb; ++j)
- {
- cin >> cur; --cur;
- if (!used[cur] && !yes)
- {
- yes = true;
- ++f;
- }
- used[cur] = true;
- sum += a[cur];
- }
- ans_mx = max(ans_mx, sum);
- ans_mn = min(ans_mn, sum);
- }
- for (int i = 0; i < n; ++i)
- if (!used[i]) rem.push_back(a[i]);
- sort(rem.begin(), rem.end());
- if (rem.size() >= nmb && f < k)
- {
- int sum1 = 0,sum2 = 0;
- for (int i = 0; i < nmb; ++i) { sum1 += rem[i]; sum2 += rem[rem.size() - 1 - i]; }
- ans_mx = max(ans_mx, sum2);
- ans_mn = min(ans_mn, sum1);
- }
- printf("%.10lf %.10lf", ans_mn * 1.0 / nmb, ans_mx * 1.0 / nmb);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement