Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <stdio.h>
- using namespace std;
- void result(vector<double> a)
- {
- sort(a.begin(), a.end());
- printf("%.10f %.10f\n", a[0], a[a.size() - 1]);
- }
- int main()
- {
- int n, k, q;
- cin >> n >> k;
- vector<int> a;
- vector<bool> was(n, true);
- vector<double> knowledge;
- for(int i = 0; i < n; i++)
- {
- int current;
- cin >> current;
- a.push_back(current);
- }
- cin >> q;
- int different = 0;
- int howMany = n / k;
- for(int i = 0; i < q; i++)
- {
- vector<int> which;
- int sum = 0;
- for(int j = 0; j < howMany; j++)
- {
- int current;
- cin >> current;
- sum += a[current - 1];
- which.push_back(current);
- }
- if (was[which[0] - 1])
- {
- different++;
- knowledge.push_back(double(sum) / howMany);
- for(int j = 0; j < howMany; j++)
- {
- was[which[j] - 1] = false;
- }
- }
- }
- if(different == k)
- {
- result(knowledge);
- }
- else
- {
- for(int i = n - 1; i > 0; i--)
- if(was[i - 1] == 0)
- a.erase(a.begin() + i - 1);
- sort(a.begin(), a.end());
- int minsum = 0, maxsum = 0;
- for(int j = 0; j < howMany; j++)
- {
- minsum += a[j];
- maxsum += a[a.size() - j - 1];
- }
- knowledge.push_back(double(minsum) / howMany);
- knowledge.push_back(double(maxsum) / howMany);
- result(knowledge);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement