You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
//#include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
const int N = 1e5 + 50;
pair<int, int> a[N];
int b[N];
int main()
{
int n, c, f;
scanf("%d%d%d", &n, &c, &f);
for (int i = 0; i < c; i++)
scanf("%d%d", &a[i].first, &a[i].second);
sort(a, a + c);
priority_queue<int> h1, h2;
for (int i = 0, x = 0; i < c; i++)
{
if (i >= (n >> 1))
{
b[i] += x;
if (a[i].second >= h1.top()) continue;
x -= h1.top(), h1.pop();
}
x += a[i].second, h1.push(a[i].second);
}
for (int i = c - 1, x = 0; i >= 0; i--)
{
if ((c - i - 1) >= (n >> 1))
{
b[i] += x;
if (a[i].second >= h2.top()) continue;
x -= h2.top(), h2.pop();
}
x += a[i].second, h2.push(a[i].second);
}
int ans = -1;
for (int i = c - 1 - (n >> 1); i >= (n >> 1) && ans == -1; i--)
if (b[i] + a[i].second <= f)
ans = a[i].first;
printf("%d", ans);
return 0;
}