題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3804
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
| #include <bits/stdc++.h> using namespace std;
int main(){ int t, m, n; cin >> t; while(t--){ cin >> m >> n; vector<int> row(m), col(n); int total = 0; for(int i=0; i<m; ++i){ cin >> row[i]; total += row[i]; } for(int i=0; i<n; ++i) cin >> col[i];
sort(row.begin(), row.end(), greater<int>()); sort(col.begin(), col.end(), greater<int>());
for(int idx = 0; idx < m; ++idx){ for(int k=0; k < row[idx] && k < n; ++k){ if(col[k]) --col[k]; else break; } sort(col.begin(), col.end(), greater<int>()); } cout << total + accumulate(col.begin(), col.end(), 0) << '\n'; } return 0; }
|