标签:style blog http color io os ar for strong
请问:挖掘机技术哪家强?AC了告诉你!
给你N(N<=3*10^4)个任务,每个任务有一个截止完成时间t(1=<t<=10^9)和完成该任务的奖励v(1=<v<=10^9),每个任务要花一天完成,问最多能获得多少奖励?
7 4 20 2 60 4 70 3 40 1 30 4 50 6 10
解题:优先队列。。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define INF 0x3f3f3f3f 15 #define pii pair<int,int> 16 using namespace std; 17 const int maxn = 100000; 18 pii d[maxn]; 19 int main(){ 20 int n,u,v; 21 priority_queue< pii,vector< pii >,greater< pii > > q; 22 while(~scanf("%d",&n)){ 23 LL ans = 0; 24 while(!q.empty()) q.pop(); 25 for(int i = 0; i < n; ++i) 26 scanf("%d %d",&d[i].first,&d[i].second); 27 sort(d,d+n); 28 for(int i = 0; i < n; ++i){ 29 if(q.size() < d[i].first){ 30 ans += d[i].second; 31 q.push(make_pair(d[i].second,d[i].first)); 32 }else if(q.size() == d[i].first){ 33 if(d[i].second > q.top().first){ 34 ans += d[i].second - q.top().first; 35 q.pop(); 36 q.push(make_pair(d[i].second,d[i].first)); 37 } 38 } 39 } 40 printf("%lld\n",ans); 41 } 42 return 0; 43 }
标签:style blog http color io os ar for strong
原文地址:http://www.cnblogs.com/crackpotisback/p/4050105.html