ATcoder Big Array
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≤i≤N), 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≤K≤b1…+…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的更多相关文章
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- Atcoder ABC155_C中有关c++ STL map的用法
题目:https://atcoder.jp/contests/abc155/tasks/abc155_c 这道题的题意是给我们n个string,让我们统计每个string出现的次数,并输出次数最多的一 ...
- AtCoder Beginner Contest 248 E - K-colinear Line // 计算几何
原题链接:E - K-colinear Line (atcoder.jp) 题意: 给出直角坐标系上N个点(N <= 300),求经过这些点中至少K个点的直线数量,若有无穷多条,则输出" ...
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- JavaScript Array对象
介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...
- 了解PHP中的Array数组和foreach
1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组 . 2.例子:一般的数组 这里,我 ...
- 关于面试题 Array.indexof() 方法的实现及思考
这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...
- javascript之活灵活现的Array
前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...
随机推荐
- 洛谷P4606 [SDOI2018]战略游戏 [广义圆方树]
传送门 思路 先考虑两点如何使他们不连通. 显然路径上所有的割点都满足条件. 多个点呢?也是这样的. 于是可以想到圆方树.一个点集的答案就是它的虚树里圆点个数减去点集大小. 可以把点按dfs序排序,然 ...
- 姿势摆好,一招学会android的布局优化!
作为android应用来讲,无论应用本身多么美观,功能多么强大,内容多么丰富.但如果App本身打开界面缓慢超过手机16ms刷新一次页面的时间,就会产生卡顿.用户体验都会变得极差,导致用户量减少.所以我 ...
- ORA-00257 archiver error. 错误的处理方法
archive log 日志已满 方法/步骤 1 SecureCRT登录服务器,切换用户oracle,连接oracle [root@userbeta~]# su - oracle [oracle@us ...
- Confluence 6 自定义配色方案
Confluence 的管理员可以修改 Confluence 的色彩配色方案.站点的默认配色方案将会在站点的默认空间上同时生效. 希望修改站点的配色方案: 在屏幕的右上角单击 控制台按钮 ,然后选择 ...
- LeetCode(94):二叉树的中序遍历
Medium! 题目描述: 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗 ...
- 彻头彻尾理解 LinkedHashMap
HashMap和双向链表合二为一即是LinkedHashMap.所谓LinkedHashMap,其落脚点在HashMap,因此更准确地说,它是一个将所有Entry节点链入一个双向链表的HashMap. ...
- python中利用上下文管理器来实现mysql数据库的封装
from pymysql import connect class DB(object): def __init__(self, password, database): # 1.连接数据库 self ...
- CAS单点登录--转载
一:单点登录介绍 单点登录( Single Sign-On , 简称 SSO )是目前比较流行的服务于企业业务整合的解决方案之一, SSO 使得在多个应用系统中,用户只需要 登录一次 就可以访问所有相 ...
- [转] 谈谈JS中的函数节流
函数节流的目的 从字面上就可以理解,函数节流就是用来节流函数从而一定程度上优化性能的.例如,DOM 操作比起非DOM 交互需要更多的内存和CPU 时间.连续尝试进行过多的DOM 相关操作可能会导致浏览 ...
- LibreOJ β Round #2
题解: 都是不错的技巧题目 t1暴力就不说了 t2dp是比较显然的 然后发现都是0,1用bitset优化 代码非常短 t3容易发现这个东西在不断合并 于是我们想到启发式合并 存疑:splay启发式合并 ...