第1行:一个数N,表示任务的数量(2 <= N <= 50000) 第2 - N + 1行,每行2个数,中间用空格分隔,表示任务的最晚结束时间E[i]以及对应的奖励W[i]。(1 <= E[i] <= 10^9,1 <= W[i] <= 10^9)
输出能够获得的最高奖励。
7 4 20 2 60 4 70 3 40 1 30 4 50 6 10
230
参考博客:http://blog.csdn.net/acdreamers/article/details/38946315
<span style="font-size:18px;">#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
struct node
{
int E;
int W;
friend bool operator<(node a,node b)
{
return a.W>b.W;
}
};
bool cmp(node a,node b)
{
return a.E<b.E;//升序
}
int main()
{
int T,i;
node a[50001];
cin>>T;
for(i=0;i<T;i++)
cin>>a[i].E>>a[i].W;
sort(a,a+T,cmp);
priority_queue<node>Q;
for(i=0;i<T;i++)
{
if(Q.size()<a[i].E)
Q.push(a[i]);
else
{
if(a[i].W>Q.top().W)
{
Q.pop();
Q.push(a[i]);
}
}
}
__int64 ans=0;
while(!Q.empty())
{
ans+=Q.top().W;
Q.pop();
}
printf("%I64d\n",ans);
return 0;
}</span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/zuguodexiaoguoabc/article/details/46940439