题解:CF2164C Dungeon
WalkerShi_ · · 题解
再不写题解社区贡献要变成0了,正好打到这道题了顺便写一下题解。
题目大意
给你
思路分析
比较显然的是我们应用 伤害最低的剑打掉那些会把剑爆掉的怪,因为不管我们通过打其它怪把伤害叠得多高,在这里打一下就碎了,不如 先用最弱的先去打交换。
然后对于那些 multiset 里,然后通过 lower_bound 二分出伤害不小于其生命值的剑,将答案加
还有
代码
换了码风,可能有点不好看,谅解一下。
#include <bits/stdc++.h>
typedef long long ll;
struct Node {
int x, y;
};
inline void solve() {
int n, m;
std::cin >> n >> m;
std::vector<int> a(n), b(m);
std::vector<Node> c(m);
std::multiset<ll> s;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
s.insert(a[i]);
}
for (int i = 0; i < m; i++)
std::cin >> b[i];
int p1 = 0, p2 = 0;
for (int i = 0; i < m; i++) {
int val;
std::cin >> val;
if (val) {
c[p1].x = b[i], c[p1].y = val;
p1++;
}
else {
b[p2] = b[i];
p2++;
}
}
auto cmp = [&](const Node &a, const Node &b) {
return a.x < b.x || (a.x == b.x && a.y > b.y);
};
std::sort(c.begin(), c.begin() + p1, cmp);
std::sort(b.begin(), b.begin() + p2);
int ans = 0;
for (int i = 0; i < p1; i++) {
auto it = s.lower_bound(c[i].x);
if (it == s.end())
break;
++ans;
int val = *it;
s.erase(it), s.insert(std::max(val, c[i].y));
}
for (int i = 0; i < p2; i++) {
auto it = s.lower_bound(b[i]);
if (it == s.end())
break;
++ans, s.erase(it);
}
printf("%d\n", ans);
}
int main() {
std::ios::sync_with_stdio(0);
int T;
std::cin >> T;
while (T--)
solve();
}
大家要是看懂了就给个赞吧!蟹蟹啦!