hdu 4544 湫湫系列故事——消灭兔子(贪心)


#include <stdio.h>  
#include <string.h>  
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define MAXN 100005
#define LL long long
int tu[MAXN]; struct Ji{ int d;
    LL p; }ji[MAXN];
priority_queue<int, vector<int>, greater<int> >que; int cmpt(int a, int b) { return a > b; } int cmpj(struct Ji a, struct Ji b) { return a.d > b.d; } int main() { int N, M; while(~scanf("%d%d", &N, &M)) { while(!que.empty())que.pop(); for(int i = 0; i < N; ++i)scanf("%d", &tu[i]);
        sort(tu, tu + N, cmpt); for(int i = 0; i < M; ++i)scanf("%d", &ji[i].d); for(int i = 0; i < M; ++i)scanf("%I64d", &ji[i].p);
        sort(ji, ji + M, cmpj);
        
        LL ans = 0; int i, j; for(i = 0, j = 0; i < N; ++i) { while((j < M) && (ji[j].d >= tu[i])) {
                que.push(ji[j].p); ++j; } if(que.empty())break;
            ans += que.top();
            que.pop(); } if(j < N) printf("No\n"); else    printf("%I64d\n", ans); } return 0; }

你可能感兴趣的:(hdu 4544 湫湫系列故事——消灭兔子(贪心))