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 (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
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
思路:数据范围不大,怎么做都行,用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;
}

被折叠的 条评论
为什么被折叠?



