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. Java的小实验——各种测试以及说明

    日期:2018.10.07 星期五 博客期:014 一.Java中的位运算 代码如下: package Morts107; public class Test107 { public static v ...

  2. verilog-testbench 时钟和复位模板

    /********************************************* ** Clocks & Reset ******************************* ...

  3. mysql数据库之基本操作和存储引擎

    一.知识储备 数据库服务器:一台计算机(对内存要求比较高) 数据库管理系统:如mysql,是一个软件 数据库:oldboy_stu,相当于文件夹 表:student,scholl,class_list ...

  4. servlet 遇到的奇怪问题

    一. servlet URl 连接多了 %09 原因value里面多了个空格 value=" value'; 改成 value="value'; 二.servlet get方法可以 ...

  5. 关于JDBC的总结

    1. Spring JDBC子框架是什么 答:就是一个Spring框架内置的持久层框架.既然是一个持久层框架,作用就是对数据库增删改查!! 2. SpringJDBC是使用声明类操作数据库的? 答:J ...

  6. poj2116 模拟题

    不知道错在哪里 /* 给定两个斐波那契表示数,要求用标准化表达方式表达 然后将这两个数加起来,和也用标准化方式表达 思路:显然要将这两个数先用十进制表示,和也用十进制表示 然后在转化成二进制即可 1 ...

  7. java反射机制实例

    1.通过数据库字段反射给对象实例赋值 convertClass.java /** * 通过反射构造对象 * @param obj * @param rs * @return */ public Obj ...

  8. Java+selenium之WebDriver的抛出异常分析(七)

    NoSuchElementException 1.检查元素的定位器是否正确 2.如果定位器正确,增加休眠时间 3.等待了足够的时间依然找不到的话,更换定位器的定位方式 NoSuchWindowExce ...

  9. 重新认识python

    为什么这样说呢,我几个月前就开始学python,但是一直都没有进步,还就只是会一些其它语言的共性的问题,也就是新学习的约等于0. 后来一直找一些适合自己的教材,通过同学找到了一个学长的教程. 开始了新 ...

  10. python with语句中的变量有作用域吗?

    一直以为python中的with语句中的变量,只在with语句块中起作用.不然为什么要缩进一个级别呢? 呵呵,然而并没有为with语句内的变量创建新的作用域. 举例: # test.py with o ...