-
Notifications
You must be signed in to change notification settings - Fork 0
/
119_B.cpp
89 lines (68 loc) · 1.08 KB
/
119_B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<iostream>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
using namespace std;
int solve(vector<int>&d, int t)
{
int sum = 0;
for(int i=0;i<t;i++)
{
sum+=d[i];
}
return sum;
}
int main()
{
int n,k;
cin>>n>>k;
vector<int>a(n);
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int t = n/k;
int q;
cin>>q;
int minm = 1000000000;
int maxm = 0;
int c[n];
memset(c,0,sizeof(c));
for(int i=0;i<q;i++)
{
int sum = 0;
for(int j=0;j<t;j++)
{
int temp;
cin>>temp;
sum+=a[temp-1];
c[temp-1] = 1;
}
minm = min(minm,sum);
maxm = max(maxm,sum);
}
vector<int>d;
for(int i=0;i<n;i++)
{
if(!c[i])
{
d.push_back(a[i]);
}
}
sort(d.begin(),d.end());
int sum = 0;
int left = n - t*k;
if((int)d.size()-left>=t)
{
maxm = max(maxm,solve(d,t));
minm = min(minm,solve(d,t));
sort(d.begin(),d.end(),greater<int>());
maxm = max(maxm,solve(d,t));
minm = min(minm,solve(d,t));
}
cout<<setprecision(10)<<(double)minm/(double)t<<" "<<(double)maxm/(double)t<<endl;
return 0;
}