提交记录:https://www.luogu.com.cn/record/101153738
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, s, w[200001], v[200001], a[200001], b[200001], y[200001], ans;
int check(int x)
{
int sum = 0;
memset(y, 0, sizeof(y));
for (int i = 1; i <= n; i++)
{
int cnt = 0, tot = 0;
for (int j = a[i]; j <= b[i]; j++)
if (w[j] >= x)
cnt++, tot += v[j];
y[i] = cnt * tot;
sum += y[i];
}
return sum;
}
signed main()
{
cin >> n >> m >> s;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
for (int i = 1; i <= m; i++)
cin >> a[i] >> b[i];
int l = 0, r = s;
while (l <= r)
{
int mid = (l + r) >> 1;
ans = check(mid);
if (ans > s)
l = mid + 1;
else
r = mid - 1;
}
cout << abs(s - ans);
return 0;
}