差分+ 贪心
#include <iostream>
#include <vector>
using namespace std;
const int N = 100010;
int n, m, k;
vector<int> b(N);
typedef long long LL;
int main(int argc, char *argv[]) {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
int t, c;
cin >> t >> c;
b[1] += c, b[t + 1] -= c;
}
for (int i = 1; i < N; i++) {
b[i] += b[i - 1];
}
LL costs{0};
int i = N - 1;
while (i > k && costs + b[i] <= m) costs += b[i--];
cout << i << endl;
return 0;
}