# 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;
}

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

## HDU Problem - 1789 Doing Homework again【贪心】

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

## HDU1789_Doing Homework again_贪心、并查集优

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth...
• yuege38
• 2017年02月19日 17:34
• 86

## HDU1789 Doing Homework again 【贪心】

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

## hdu 1789 Doing Homework again 贪心算法

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

## hdu 1789 Doing Homework again（简单贪心）

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...
• opm777
• 2014年01月23日 13:58
• 970

## 【贪心】HDU-1789 Doing Homework again

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

## hdu1789Doing Homework again【贪心算法】

#include #include using namespace std; //题意：有一组作业，每个作业都有自己的最后期限和分数，只要改作业在自己的最后期限之前完成都可以拿分， //每一种...

举报原因： 您举报文章：HDU 1789 Doing Homework again 贪心 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)