Problem Statement

There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤iN)bi copies of an integer ai are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array {1,2,2,3,3,3}is 3.

Constraints

  • 1≤N≤105
  • 1≤ai,bi≤105
  • 1≤Kb1…+…bn
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

  1. N K
  2. a1 b1
  3. :
  4. aN bN

Output

Print the K-th smallest integer in the array after the N operations.

Sample Input 1

  1. 3 4
  2. 1 1
  3. 2 2
  4. 3 3

Sample Output 1

  1. 3

The resulting array is the same as the one in the problem statement.

Sample Input 2

  1. 10 500000
  2. 1 100000
  3. 1 100000
  4. 1 100000
  5. 1 100000
  6. 1 100000
  7. 100000 100000
  8. 100000 100000
  9. 100000 100000
  10. 100000 100000
  11. 100000 100000

Sample Output 2

  1. 1
  2.  
  3. 思路:用结构体排序讲a先从小到大排一边,然后再挑选出只要b的总合大于K的结构体然后输出就行
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e5+10;
  4. struct str
  5. {
  6. long long p,q;
  7. }a[N];
  8. bool cmp( str x, str y) //结构体排序按a的值从小到大排
  9. {
  10. return x.p<y.p;
  11. }
  12. int main()
  13. {
  14. long long m,n,i;
  15. cin>>m>>n;
  16. for(i = 0; i < m; i++){
  17. cin>>a[i].p>>a[i].q;
  18. }
  19. sort(a,a+m,cmp);
  20. long long sum = 0;
  21. for(i = 0; i < m; i++){
  22. sum += a[i].q;
  23. if(sum >= n){ //挑选出符合条件的然后输出
  24. cout<<a[i].p<<endl;
  25. break;
  26. }
  27. }
  28. return 0;
  29. }

  

  1.  

ATcoder Big Array的更多相关文章

  1. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  2. Atcoder ABC155_C中有关c++ STL map的用法

    题目:https://atcoder.jp/contests/abc155/tasks/abc155_c 这道题的题意是给我们n个string,让我们统计每个string出现的次数,并输出次数最多的一 ...

  3. AtCoder Beginner Contest 248 E - K-colinear Line // 计算几何

    原题链接:E - K-colinear Line (atcoder.jp) 题意: 给出直角坐标系上N个点(N <= 300),求经过这些点中至少K个点的直线数量,若有无穷多条,则输出" ...

  4. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

  5. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  6. JavaScript Array对象

    介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...

  7. 了解PHP中的Array数组和foreach

    1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组    . 2.例子:一般的数组 这里,我 ...

  8. 关于面试题 Array.indexof() 方法的实现及思考

    这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...

  9. javascript之活灵活现的Array

    前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...

随机推荐

  1. 洛谷P4606 [SDOI2018]战略游戏 [广义圆方树]

    传送门 思路 先考虑两点如何使他们不连通. 显然路径上所有的割点都满足条件. 多个点呢?也是这样的. 于是可以想到圆方树.一个点集的答案就是它的虚树里圆点个数减去点集大小. 可以把点按dfs序排序,然 ...

  2. 姿势摆好,一招学会android的布局优化!

    作为android应用来讲,无论应用本身多么美观,功能多么强大,内容多么丰富.但如果App本身打开界面缓慢超过手机16ms刷新一次页面的时间,就会产生卡顿.用户体验都会变得极差,导致用户量减少.所以我 ...

  3. ORA-00257 archiver error. 错误的处理方法

    archive log 日志已满 方法/步骤 1 SecureCRT登录服务器,切换用户oracle,连接oracle [root@userbeta~]# su - oracle [oracle@us ...

  4. Confluence 6 自定义配色方案

    Confluence 的管理员可以修改 Confluence 的色彩配色方案.站点的默认配色方案将会在站点的默认空间上同时生效. 希望修改站点的配色方案: 在屏幕的右上角单击 控制台按钮 ,然后选择  ...

  5. LeetCode(94):二叉树的中序遍历

    Medium! 题目描述: 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗 ...

  6. 彻头彻尾理解 LinkedHashMap

    HashMap和双向链表合二为一即是LinkedHashMap.所谓LinkedHashMap,其落脚点在HashMap,因此更准确地说,它是一个将所有Entry节点链入一个双向链表的HashMap. ...

  7. python中利用上下文管理器来实现mysql数据库的封装

    from pymysql import connect class DB(object): def __init__(self, password, database): # 1.连接数据库 self ...

  8. CAS单点登录--转载

    一:单点登录介绍 单点登录( Single Sign-On , 简称 SSO )是目前比较流行的服务于企业业务整合的解决方案之一, SSO 使得在多个应用系统中,用户只需要 登录一次 就可以访问所有相 ...

  9. [转] 谈谈JS中的函数节流

    函数节流的目的 从字面上就可以理解,函数节流就是用来节流函数从而一定程度上优化性能的.例如,DOM 操作比起非DOM 交互需要更多的内存和CPU 时间.连续尝试进行过多的DOM 相关操作可能会导致浏览 ...

  10. LibreOJ β Round #2

    题解: 都是不错的技巧题目 t1暴力就不说了 t2dp是比较显然的 然后发现都是0,1用bitset优化 代码非常短 t3容易发现这个东西在不断合并 于是我们想到启发式合并 存疑:splay启发式合并 ...