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:

N K
a1 b1
:
aN bN

Output

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

Sample Input 1

3 4
1 1
2 2
3 3

Sample Output 1

3

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

Sample Input 2

10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000

Sample Output 2

1

思路:用结构体排序讲a先从小到大排一边,然后再挑选出只要b的总合大于K的结构体然后输出就行
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
struct str
{
long long p,q;
}a[N];
bool cmp( str x, str y) //结构体排序按a的值从小到大排
{
return x.p<y.p;
}
int main()
{
long long m,n,i;
cin>>m>>n;
for(i = 0; i < m; i++){
cin>>a[i].p>>a[i].q;
}
sort(a,a+m,cmp);
long long sum = 0;
for(i = 0; i < m; i++){
sum += a[i].q;
if(sum >= n){ //挑选出符合条件的然后输出
cout<<a[i].p<<endl;
break;
}
}
return 0;
}

  

												

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. python的学习笔记

    1逻辑运算符不理解 2 在交互模式中,最后被输出的表达式结果被赋值给变量 _ .例如: >>> tax = 12.5 / 100 >>> price = 100.5 ...

  2. Confluence 6 Windows 中以服务方式自动重启修改运行服务的用户

    基于安全的考虑,如果你希望你的 Confluence 不是在系统中以管理员的身份运行或者你使用网络驱动器来存储备份,附件和索引的话,你可以以其他用户来运行 Confluence. 希望修改用户,打开 ...

  3. 整合 JIRA 和 Confluence 6

    Jira 应用和 Confluence 可以完全的整合在一起.在 Confluence 中收集你项目组成员的想法,知识和计划.在 Jira 中跟踪你的系统出现的问题,让这 2 个应用同时工作. 了解更 ...

  4. Confluence 6 发送 Confluence 通知到其他 Confluence 服务器

    你可以配置 Confluence 服务器向其他的 Confluence 服务器发送消息.在这种情况下,Confluence 服务器将不会显示 workbox. 希望发送消息到其他 Confluence ...

  5. Confluence 6 管理员联系表单的后台配置界面

    管理员联系表单的后台配置界面截图和配置. 对输入的数据进行编辑和选择是否启用发送电子邮件给管理员 https://www.cwiki.us/display/CONFLUENCEWIKI/Configu ...

  6. 图片文字css小知识点

    行内元素,图片和文字中间有缝隙,需要给父元素设置font-size:0: 图片和文字不对齐,给图片设置vertical-align:top 文字行高有缝隙 设置vertical-align:top  

  7. laravel 服务提供者

    服务提供者,在laravel里面,其实就是一个工厂类.它最大的作用就是用来进行服务绑定.当我们需要绑定一个或多个服务的时候,可以自定义一个服务提供者,然后把服务绑定的逻辑都放在该类的实现中.在lara ...

  8. 小学生都看得懂的C语言入门(5): 指针

    现在已经学到C语言的后面了, 快学完咯.... (一)取地址运算 先来看一下sizeof 计算所占字节 #include<stdio.h> int main() { int a; a=; ...

  9. h5 video标签的使用

     标签的布置 <video src="1.mp4" poster="1.jpg" id="vid" controls> 你的浏览 ...

  10. sass基础—具体编译步骤及对应命令:详细

    /*基础语法*/h1{ color: red;} /*变量定义*/ $color: red; /*嵌套*/body{ header{ } footer{ }} /*mixin函数*/@mixin al ...