提交时间:2026-04-15 20:16:21
运行 ID: 436475
#include <iostream> #include <algorithm> using namespace std; const int MAX = 100005; int def[MAX], atk[MAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); int M, N; cin >> M >> N; for (int i = 0; i < M; i++) cin >> def[i]; for (int i = 0; i < N; i++) cin >> atk[i]; sort(def, def + M); sort(atk, atk + N); int d = 0, a = 0; while (d < M && a < N) { if (atk[a] > def[d]) { d++; } a++; } long long ans = 0; if (d == M) { for (int i = a; i < N; i++) { ans += atk[i]; } } cout << ans; return 0; }