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 ...
随机推荐
- Cropper.js使用笔记
官网:https://fengyuanchen.github.io/cropperjs/ github:https://github.com/fengyuanchen/cropperjs 由于文档不好 ...
- RCNN--目标检测
原博文:http://www.cnblogs.com/soulmate1023/p/5530600.html 文章简要介绍RCNN的框架,主要包含: 原图-->候选区域生成-->对每个候选 ...
- NSLayoutConstraint 使用详解 VFL使用介绍
注意 使用前必须先取消所有的你想设置View 的 Autoresizing 属性 因为 Autoresizing Layout不能共存 系统默认是 Autoresizing for v in su ...
- mabatis的批量新增sql 初级的 初级的 初级的
简单描述:做开发的时候,会遇到一次插入好多条记录,怎么做好呢? 解决思路:循环insert啊! 哪凉快那呆着去←!← 这样会增加数据库开销的,当然不能这么干了,要在sql上下功夫.看代码,一下就明 ...
- cf1076d 贪心最短路
#include<bits/stdc++.h> #include<queue> using namespace std; #define maxn 300005 #define ...
- MySQL源码安装一键脚本
#红色部分根据自己的需求来定义#!/bin/bash #卸载系统自带的Mysql /bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps /bi ...
- json数据转为Map集合
我是利用Gson来弄得Gson gson = new Gson();//显得出HashMap的类型Type type = new TypeToken<HashMap<String, Str ...
- babelrc
.babelrc文件 // 简单版 { "presets": ["es2015", "stage-2"], // 使用 es2015 npm ...
- signal() 和 sigaction()
[摘自<Linux/Unix系统编程手册>] Unix系统提供了两种方式来改变信号处置:signal() 和 sigaction(). signal() 的行为在不同Unix实现间存在差异 ...
- [转]Centos 查看端口占用情况和开启端口命令
http://www.cnblogs.com/xqzt/p/4919191.html 1.Centos 查看端口占用 比如查看 80 端口占用情况使用如下命令: lsof -i tcp:80 2.列出 ...