消灭兔子

/*
差不多的思路,很容易想到按照兔子血量降序排序
之后按照箭的攻击力降序排序,然后把可以杀死兔子的箭全放入小根堆中,选择一个Q币最小的用
*/
#include <bits/stdc++.h>
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
typedef long long LL;
const int N = 1e5 + 10, M = N, mod = 1e9 + 7;
using namespace std;
int a[N];
struct node{
	int d, p;
}b[N];
bool cmp1(int x, int y){
	return x > y;
}
bool cmp2(node x, node y){
	return x.d > y.d;
}
int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= m; i ++) cin >> b[i].d;
	for(int i = 1; i <= m; i ++) cin >> b[i].p;
	sort(a + 1, a + 1 + n, cmp1);
	sort(b + 1, b + 1 + m, cmp2);
	LL ans = 0;
	int idx = 1;
	priority_queue<int, vector<int>, greater<int>> q;
	for(int i = 1; i <= n; i ++){
		while(idx <= m && b[idx].d >= a[i]){
			q.push(b[idx].p);
			idx ++;
		}
		if(q.empty()){
			cout << "No" << endl;
			return 0;
		}
		ans += q.top();
		q.pop();
	}
	cout << ans;
    return 0;
}
posted @ 2024-02-02 16:17  可爱的卤蛋  阅读(33)  评论(0编辑  收藏  举报