包关注包关注包关注qwq
能过样例但爆零
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2 * 1e5+5;
int n, m, ss;
int wmax, wmin;
int ww;
int y;
int c;
int a[N], b[N];
int l[N],r[N];
int w[N], v[N], s[N];
bool he(int ww)
{
int s1 = 0, s2 = 0;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 1; i <= n; i++)
{
if (w[i] >= ww)
{
a[i] = a[i - 1] +1;
b[i] = b[i - 1] + v[i];
}
else
{
a[i] = a[i - 1];
b[i] = b[i - 1] ;
}
}
for (int i = 1; i <=m; i ++)
{
int lll= l[i], rrr= r[i];
s1 += a[rrr] - a[lll - 1];
s2 += b[rrr] - b[lll - 1];
}
y = s1*s2;
if (y > ss) return 1;
else return 0;
}
signed main()
{
cin >> n >> m >> ss;
int ans = ss;
for (int i = 1; i <= n; i++)cin >> w[i] >> v[i], wmax = max(wmax, w[i]), wmin = min(wmin, w[i]);
for (int i = 1; i <=m; i++)cin >>l[i]>>r[i];
int ll = wmin-1, rr = wmax;
while (ll <= rr)
{
int mid = ll + (rr - ll) / 2;
if (he(mid)) ll = mid + 1;
else rr = mid - 1;
ans = min(ans, abs(y - ss));
}
cout << ans;
}