题目链接:http://codeforces.com/gym/101064/problem/D

问你两个数组合相加的第k大数是多少。

先sort数组,二分答案,然后判断其正确性(判断过程是枚举每个数然后二分)。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
LL a[N], k, n; bool judge(LL val) {
LL cnt = ;
for(int i = ; i <= n; ++i) {
LL pos = (LL)(upper_bound(a + , a + n + , val - a[i]) - a);
if(pos > (LL)i)
cnt += n - pos + ;
else
cnt += n - pos;
}
cnt /= ;
return (n - )*n/ - k >= cnt;
} int main()
{
while(~scanf("%lld %lld", &n, &k)) {
for(int i = ; i <= n; ++i) {
scanf("%lld", a + i);
}
sort(a + , a + n + );
LL l = a[] + a[], r = a[n] + a[n - ];
while(l < r) {
LL mid = (l + r) / ;
if(judge(mid)) {
r = mid;
} else {
l = mid + ;
}
}
printf("%lld\n", l);
}
return ;
}

Gym 101064 D Black Hills golden jewels (二分)的更多相关文章

  1. Gym 101064 D Black Hills golden jewels 【二分套二分/给定一个序列,从序列中任意取两个数形成一个和,两个数不可相同,要求求出第k小的组合】

    D. Black Hills golden jewels time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. D. Black Hills golden jewels 二分答案 + 二分判定

    http://codeforces.com/gym/101064/problem/D 题目是给定一个数组,如果两两组合,有C(n, 2)种结果,(找出第一个大于等于第k大的结果) 思路, 二分答案va ...

  3. Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  4. Gym - 100283F F. Bakkar In The Army —— 二分

    题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...

  5. Gym - 101002K:YATP (树分治+二分+斜率优化)

    题意:给定带点权边权的树,定义路径的花费=路径边权和e+起点点权w[s]*终点点权w[t].N<2e5,e,w<1e6: 思路:首先,需要树分治. 然后得到方程dp[i]=min{ dis ...

  6. Gym - 100283F Bakkar In The Army(二分)

    https://vjudge.net/problem/Gym-100283F 题意: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 .... 给出这样的序列,然后给出一个n,计算从1 ...

  7. Gym 101128J Saint John Festival(凸包 + 二分判点和凸包关系)题解

    题意:给你一堆黑点一堆红点,问你有最多几个黑点能找到三个红点,使这个黑点在三角形内? 思路:显然红点组成的凸包内的所有黑点都能做到.但是判断黑点和凸包的关系朴素方法使O(n^2),显然超时.那么我现在 ...

  8. gym 101064 G.The Declaration of Independence (主席树)

    题目链接: 题意: n个操作,有两种操作: E p  c    在序号为p的队列尾部插入c得到新的队列,序号为i D p   查询并删除序号为p的队列顶部的元素,得到序号为i的新队列 思路: 需要查询 ...

  9. GYM 101064 2016 USP Try-outs G. The Declaration of Independence 主席树

    G. The Declaration of Independence time limit per test 1 second memory limit per test 256 megabytes ...

随机推荐

  1. mongodb主从复制

    1)主服务器--master --port 20001 2)从服务器--slave --source 127.0.0.1:20001 --port 20002 注释:--master 以主服务器形式启 ...

  2. BZOJ 1078 斜堆

    感谢MATO大神的博客 http://www.cppblog.com/MatoNo1/archive/2013/03/03/192131.html 注意细节. #include<iostream ...

  3. BZOJ 4408 神秘数

    题解同各神犇的方法... #include<iostream> #include<cstdio> #include<cstring> #include<alg ...

  4. 【转】gcc中-pthread和-lpthread的区别

    原文网址:http://chaoslawful.iteye.com/blog/568602 用gcc编译使用了POSIX thread的程序时通常需要加额外的选项,以便使用thread-safe的库及 ...

  5. Linux/Unix shell 监控Oracle告警日志(monitor alter log file)

    使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linu ...

  6. 百度地图Api详解之地图标注

    标注概述 标注(Marker)是用来表示一个点位置的可见元素,每个标注自身都包含地理信息.比如你在西单商场位置添加了一个标注,不论地图移动.缩放,标注都会跟随一起移动,保证其始终指向正确的地理位置. ...

  7. beginUpdates和endUpdates

    我们在做UITableView的修改,删除,选择时,需要对UITableView进行一系列的动作操作. 这样,我们就会用到 [tableView beginUpdates]; if (newCount ...

  8. C# Datatable的Select方法

    lubiaopan 原文 Datatable的Select()方法简介 DataTable是我们在进行开发时经常用到的一个类,并且经常需要对DataTable中的数据进行筛选等操作,下面就介绍一下Da ...

  9. crontab的安装及crontab命令介绍

    前一天学习了 at 命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个 ...

  10. $(document).ready()并不靠谱

    好多用过jQuery的朋友都为jQuery的强大功能和易用性折服,有了jQuery菜鸟也能做javascript特效,有了jQuery高手写代码的效率会进一步提升. 学习jQuery的第一课就是学会在 ...