码迷,mamicode.com
首页 > 其他好文 > 详细

HDU1789 Doing Homework again

时间:2017-10-11 10:41:01      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:stream   empty   strong   pop   while   pre   mes   lib   dea   

基础单调队列:

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<memory.h>
#include<queue>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
struct in
{
    int d,s;//deadline,score
}c[1010];
bool cmp(in a,in b){
    return a.d<b.d;
}
int main()
{
    int T,n,i,j,t,cnt,ans;
    scanf("%d",&T);
    while(T--){
        cnt=ans=0;
        t=0;
        while(!q.empty()) q.pop();
        scanf("%d",&n);
        for(i=1;i<=n;i++) scanf("%d",&c[i].d);
        for(i=1;i<=n;i++) scanf("%d",&c[i].s);
        sort(c+1,c+n+1,cmp);
        for(i=1;i<=n;i++){
            q.push(c[i].s);
            if(c[i].d>t)  t++;
            else {
                ans+=q.top();q.pop();
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

HDU1789 Doing Homework again

标签:stream   empty   strong   pop   while   pre   mes   lib   dea   

原文地址:http://www.cnblogs.com/hua-dong/p/7648852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!