| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 436414 | 顾鑫辰 | 【C6-7】母舰 | C++ | 解答错误 | 0 | 41 MS | 1032 KB | 1273 | 2026-04-14 16:52:00 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { // m = 防御系统数,n = 攻击系统数 int m, n; cin >> m >> n; vector<int> defense(m); // 对方防御 vector<int> attack(n); // 己方攻击 // 输入防御值 for (int i = 0; i < m; i++) { cin >> defense[i]; } // 输入攻击值 for (int i = 0; i < n; i++) { cin >> attack[i]; } // 排序:从小到大 sort(defense.begin(), defense.end()); sort(attack.begin(), attack.end()); int damage = 0; // 总伤害 int d_idx = 0; // 当前要破的防御 int a_idx = 0; // 当前用的攻击 // 贪心:用最小的能破防的攻击去破防 while (d_idx < m && a_idx < n) { if (attack[a_idx] > defense[d_idx]) { // 破掉一个防御 d_idx++; a_idx++; } else { // 破不了,留着打本体 damage += attack[a_idx]; a_idx++; } } // 剩下所有攻击都打本体 while (a_idx < n) { damage += attack[a_idx]; a_idx++; } cout << damage << endl; return 0; }