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. Elasticsearch入门,这一篇就够了

    实时搜索引擎Elasticsearch Elasticsearch(简称ES)是一个基于Apache Lucene(TM)的开源搜索引擎,无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进 ...

  2. java常见命名规则

    常见命名规则: 包:类似文件夹,用于把相同的类名进行区分(小写) 单级:例如:student 多级:例如:cn.student 类或者接口: 一个单词:单词首字母大写,例如:Student 多个单词: ...

  3. 在Ubuntu 15下搭建V/P/N服务器pptpd安装和配置

    在Ubuntu 15下搭建VPN服务器pptpd安装和配置 在ubuntu下配置vpn的方式有很多种,其中比较常见的是pptpd,它配置简单,但是安全性不高,不过对于一般使用来说足够了,我按照程搭建了 ...

  4. Hive shell 基本命令

    首先连接 hive shell 直接输入 hive启动, 使用--开头的字符串来表示注释 hive>quit; --退出hive hive> exit; --exit会影响之前的使用,所以 ...

  5. EasyUI Layout 添加、删除、折叠、展开布局

    <!DOCTYPE html> <html> <head> <title>吹泡泡的魚-主页</title> <link rel=&qu ...

  6. 初识dubbo

    1. 为什么需要 Dubbo(摘自http://dubbo.apache.org/zh-cn/docs/user/quick-start.html) 随着互联网的发展,网站应用的规模不断扩大,常规的垂 ...

  7. 【ES】学习10-聚合3

    聚合是在查询匹配的文档中做统计的 不指定查询语句时,从所有文档中匹配. 下面两个语句等价: GET /cars/transactions/_search { , "aggs" : ...

  8. Nginx详解三:Nginx基础篇之yum安装

    Nginx快速搭建 Mainline version ----开发版:具有最新功能的版本,用于测试.研究.学习,不用于企业生成环境 Stable version----稳定版:官方认可,且通过测试的 ...

  9. txt提取文件中包含特定内容的内容

    @set/p str= 请输入要查找的内容: findstr " >%~1_查找内容.txt

  10. 论文阅读笔记八:SegNet: A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation (IEEE2017)

    原文链接:https://arxiv.org/pdf/1511.00561.pdf github(tensorflow):https://github.com/aizawan/segnet 基于Seg ...