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 ...
随机推荐
- 在v-html中,js 正则表达式清除字符串里的style属性
项目中遇到这样的需求,后端返回的是字符串,在vue用v-html显示,里面有style样式,要去除style 在v-html中使用filters,和平时的不一样,推荐项目的方法,定义一个全局的过滤方法 ...
- 10分钟了解Android的事件分发
什么是事件分发? 大家知道Android中的视图是由一个个View嵌套构成的层级视图,即一个View里包含有子View,而这个子View里面又可以再添加View.当用户触摸屏幕产生一系列事件时,事件会 ...
- Linux端BaiduPCS-Go使用方法
下载https://pan.baidu.com/s/1RFHTRE1c_JlP8rrZiERsTg 运行 ./BaiduPCS-Go 可能更新:update 登录:login 下载: d xxx 更多 ...
- php可变数量的参数
PHP 在用户自定义函数中支持可变数量的参数列表.在 PHP 5.6 及以上的版本中,由 ... 语法实现:在 PHP 5.5 及更早版本中,使用函数 func_num_args(),func_get ...
- border画梯形
<!doctype html><html lang="en"> <head> <meta charset="UTF-8&quo ...
- uva11865 二分流量+最小生成树
uva好题真多 本题用二分法找flow,把流量小于flow的全部筛掉,剩下的边建立最小树形图,如果权值大于c或者不能建图,那么修改二分边界 上代码,觉得最小树形图的代码很优美 /* 题意:给定n个点, ...
- easyui之自定义字体图标(鼠标覆盖时切换颜色)
项目要求是自定义字体图标,使用easyui框架结构,众所周知easyui强功能弱样式,字体图标其实就是一张图片.要达到切换图标颜色的效果,要么就是有两套图,使用js控制.但是我这个人比较懒,不喜欢做复 ...
- Yslow web性能测试插件
YSlow可以对网站的页面进行分析,并告诉你为了提高网站性能,如何基于某些规则而进行优化. YSlow可以分析任何网站,并为每一个规则产生一个整体报告,如果页面可以进行优化,则YSlow会列出具体的修 ...
- IDEA复制项目操作
- windows环境下永久修改pip镜像源的方法(转)
一.在windows环境下修改pip镜像源的方法(以python3.7为例) (1):在windows文件管理器中,输入 %APPDATA%,cmd里面输入即可. (2):会定位到一个新的目录下,在该 ...