AtCoder:Big Array(思维)

C - Big Array


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

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 (1iN)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

  • 1N105
  • 1ai,bi105
  • 1Kb1+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

Copy
3 4
1 1
2 2
3 3

Sample Output 1

Copy
3

The resulting array is the same as the one in the problem statement.


Sample Input 2

Copy
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

Copy
1
题意:给出b[i]个a[i],i属于[1,N],组成一个数列,问第K小的数是什么。

思路:数据范围不大,怎么做都行,用set练练手。

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
multiset<pair<LL, LL> >s;
int main()
{
    LL n, k, a, b;
    scanf("%lld%lld",&n,&k);
    while(n--)
    {
        scanf("%lld%lld",&a,&b);
        s.insert(make_pair(a, b));
    }
    LL sum = 0;
    for(auto it = s.begin(); it!=s.end(); ++it)
    {
        sum += it->second;
        if(sum >= k)
            return 0*printf("%d\n",it->first);
    }
    return 0;
}



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值