摘要

题目链接 难度等级 完成状态 完成分数 最后编辑时间 需要注意
地鼠游戏 ★☆☆☆☆ 答案正确 100 2015-7-19 16:59:43

代码

1052.cpp代码已折叠
展开折叠内容
显示/移除行号
  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<set>
  5. #include<queue>
  6. using namespace std;
  7. #define time first
  8. #define val second
  9. pair<int,int> a[10000]={};
  10. priority_queue<pair<int,int>>u;//默认大根堆//
  11. int n;
  12. int main(){
  13. cin>>n;
  14. for(int i=1;i<=n;++i)
  15. cin>>a[i].time;
  16. for(int i=1;i<=n;++i)
  17. cin>>a[i].second;
  18. sort(a+1,a+n+1);
  19. int ans=0;
  20. for(int t=a[n].time,qi=n;t>=1;--t)//t从后往前枚举每一个时间//
  21. {
  22. while(a[qi].time==t){
  23. u.push(make_pair(a[qi].val,a[qi].time));//地鼠消失之前,扔到堆里//
  24. --qi;
  25. }
  26. if(!u.empty())
  27. {
  28. ans+=u.top().first;//每次取价值最高的//
  29. u.pop();
  30. }
  31. }
  32. cout<<ans<<endl;
  33. }
  34.  

著作权声明[编辑]

关于[编辑]