# HDU 1789 Doing Homework again 贪心

#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int n;
struct node
{
int dl,sec;
friend bool operator <(const node &a,const node &b)
{
return a.sec>b.sec;
}
}hw[1000+5];
priority_queue<node>q;
bool cmp(node a,node b)
{
if(a.dl==b.dl) return a.sec>b.sec;
else return a.dl<b.dl;
}
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
scanf("%d",&n);
while(!q.empty()) q.pop();
for(int i=1;i<=n;i++)
{
scanf("%d",&hw[i].dl);
}
for(int i=1;i<=n;i++)
{
scanf("%d",&hw[i].sec);
}
sort(hw+1,hw+1+n,cmp);
int sum=0,day=1;
for(int i=1;i<=n;i++)
{
if(hw[i].dl<day)
{
q.push(hw[i]);
node k=q.top();
q.pop();
sum+=k.sec;
}
else
{
q.push(hw[i]);
day++;
}
}
printf("%d\n",sum);
}
return 0;
}

• 本文已收录于以下专栏：

## 【贪心】 hdu1789 Doing Homework again

Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description ...

## HDU 1789 Doing Homework again（贪心算法）

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...

## hdu1789 Doing Homework again （贪心+优先队列）

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...

## HDU 1789 Doing Homework again(贪心)

Doing Homework again Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Ot...

## hdu1789(Doing Homework again 贪心)

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth...

## HDU 1789 Doing Homework again (贪心)

HDU 1789 Doing Homework again (贪心)

## hdu 1789 Doing Homework again（贪心）

Doing Homework againProblem Description Ignatius has just come back school from the 30th ACM/ICPC. ...

## HDU 1789 Doing Homework again 贪心

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)