forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path261A.cpp
50 lines (38 loc) · 838 Bytes
/
261A.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
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
int q[100000],a[100000];
int main(){
ios::sync_with_stdio(0);
int n,m;
cin >> n;
for(int i = 0;i < n;++i)
cin >> q[i];
sort(q,q + n);
cin >> m;
for(int i = 0;i < m;++i)
cin >> a[i];
sort(a,a + m);
int Q = q[0];
int pos = m - 1;
long long ans = 0;
while(pos >= 0){
int s = max(0,pos - Q + 1);
//cout << s << " " << pos << endl;
for(int i = s;i <= pos;++i) ans += a[i];
pos = s - 3;
//cout << pos << endl;
}
cout << ans << '\n';
return 0;
}