题意:

求子集和第k大,n,k<=1e6

思路:

优先队列经典题目,注意优先队列是默认按从大到小排的

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 4e5+;
const int maxm = 4e5+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int n, k;
ll a[maxn];
priority_queue<pair<ll, int> ,vector<pair<ll,int>>, greater<pair<ll,int>> >q; //priority_queue<pair<ll,int>, vector<pair<ll,int> >, greater<pair<ll,int> > >q;
int main(){
scanf("%d %d", &n, &k);
for(int i = ; i <= n; i++){
scanf("%lld", &a[i]);
}
sort(a+,a++n);
q.push({a[],});
int cnt = ; while(cnt < k){
auto tmp = q.top();
q.pop();
ll ans = tmp.fst;
int id = tmp.sc;
if(id < n){
q.push({ans+a[id+],id+});
q.push({ans-a[id]+a[id+], id+});
}
cnt++;
if(cnt == k){
printf("%lld\n", ans);
break;
}
}
return ;
}

最新文章

  1. eclipse maven maven-archetype-webapp 创建失败
  2. Linux 系统中僵尸进程
  3. SharePoint Server 2013开发之旅(一):新的开发平台和典型开发场景介绍
  4. sublime Text3使用笔记
  5. 因用了NeatUpload大文件上传控件而导致Nonfile portion &gt; 4194304 bytes错误的解决方法
  6. 第2章 Posix IPC
  7. (转载)delphi 常用函数(数学)
  8. [RxJS] Error Handling in RxJS
  9. meta标签的少许语法,慢慢收集中...
  10. iOS英语—》中国本土化,如调用专辑,摄像头的变化“cancel”,“photos”至“撤消”,“摄像头”
  11. IDEA内存异常问题
  12. Python实现Mysql数据库连接池
  13. CentOS7.4使用KVM
  14. 使用.net core efcore根据数据库结构自动生成实体类
  15. SpringMvc的基本流程
  16. 第四十一课 KMP子串查找算法
  17. Leaflet.draw 无法编辑multipolygon类型多边形 解决方法
  18. .NetCore使用Swagger进行单版本或多版本控制处理
  19. I/O模型(同步、非同步、阻塞、非阻塞)总结
  20. 允许root远程登录Solaris

热门文章

  1. Go指针,如此轻松掌握,希望有收获
  2. OpenStack Identity API v3 extensions (CURRENT)
  3. (2)MongoDB副本集自动故障转移原理
  4. DP-直线分割递推
  5. &lt;a&gt;标签的href和onclick属性【转】
  6. [bzoj4569] [loj#2014] [Scoi2016] 萌萌哒
  7. sense8影评摘抄
  8. python  获取网页图片 十月底的 一弹
  9. 生成URL(而不是链接) Generating URLs (and Not Links) | 在视图中生成输出URL |高级路由特性 | 精通ASP-NET-MVC-5-弗瑞曼
  10. GCC编译Win图形程序不显示控制台方法