求如调45分!
#include<iostream>
using namespace std;
#define ll long long
int main() {
ll n, m, s;
cin >> n >> m >> s;
ll v1[200010];
ll v2[200010];
ll v3[200010];
ll v4[200010];
ll r = 0;
ll l = 100000000;
for (ll i = 1;i <= n;i++) {
ll w, v;
cin >> w >> v;
v1[i] = w;
v2[i] = v;
r = max(r, w);
l = min(r, w);
}
ll mid;
ll ans[200010][2];
ll minl = 100000000;
for (ll i = 0;i < m;i++) {
ll a, b;
cin >> a >> b;
ans[i][0] = a;
ans[i][1] = b;
}
while (r >= l) {
mid = l + (r - l) / 2;
for (ll i = 1;i <= n;i++) {
if (v1[i] >= mid)v3[i] = v3[i - 1] + 1, v4[i] = v4[i - 1] + v2[i];
else v3[i] = v3[i - 1], v4[i] = v4[i - 1];
}
ll sum = 0;
for (ll i = 0;i < m;i++) {
sum += (v3[ans[i][1]] - v3[ans[i][0] - 1]) * (v4[ans[i][1]] - v4[ans[i][0] - 1]);
}
if (sum >= s) {
l = mid + 1;
}
else {
r = mid - 1;
}
ll x = abs(s - sum);
minl = min(minl, x);
}
cout << minl;
return 0;
}