11292 Dragon of Loowater
阿新 • • 發佈:2019-02-14
題目:
貪心即可,直接用sort排序就可以了。
程式碼:
#include<iostream> #include<algorithm> using namespacestd; int ln[20000], lm[20000]; int main() { int n, m, sum; while (cin >> n >> m) { if (n == 0)break; for (int i = 0; i < n; i++)cin >> ln[i]; for (int i = 0; i < m; i++)cin >>lm[i]; sort(ln, ln + n); sort(lm, lm + m); sum = 0; int i, j; for (i = 0, j = 0; i < n && j < m; j++)if (lm[j] >= ln[i]) { sum += lm[j]; i++; } if (i == n)cout << sum << endl; else cout << "Loowater is doomed!" << endl; } return 0; }