提交时间:2026-04-15 20:16:52
运行 ID: 436476
#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_top = M - 1; int a_top = N - 1; int break_cnt = 0; while (d_top >= 0 && a_top >= 0) { if (atk[a_top] > def[d_top]) { break_cnt++; a_top--; d_top--; } else { a_top--; } } // 计算剩下所有攻击的和 long long ans = 0; if (break_cnt == M) { for (int i = 0; i <= a_top; i++) { ans += atk[i]; } } cout << ans << endl; return 0; }