solution-at2561
AT2561题解
posted on 2022-05-07 15:16:14 | under 题解 | source
我们可以用一个优先队列储存每一个区间的数值和长度,然后再求第 \(k\) 位的值。
代码:
#include<bits/stdc++.h>
using namespace std;
struct node{
long long int id,x;
node(){}
node(int a,int b){id=a,x=b;}
bool operator<(const node &t)const{
return id>t.id;
}
};
priority_queue<node>q;
long long int n,k,a,b;//不开long long见祖宗
int main()
{
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++)scanf("%lld%lld",&a,&b),q.push(node(a,b));
while(k>q.top().x)k-=q.top().x,q.pop();
printf("%lld",q.top().id);
return 0;
}

浙公网安备 33010602011771号