1 条题解

  • -1
    @ 2024-7-26 11:07:34
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 2e5+10;
    ll n, m, s;
    ll ans = 1e18;
    ll sum[N], sumv[N];
    struct Ore{
    	ll w, v;
    }A[N], B[N];
    bool check(ll W){
    	memset(sum, 0, sizeof sum);
    	memset(sumv, 0, sizeof sumv);
    	for (int i = 1; i <= n; i ++){
    		if(A[i].w >= W){
    			sum[i] = sum[i-1] + 1;
    			sumv[i] = sumv[i-1] + A[i].v;
    		}else{
    			sum[i] = sum[i-1];
    			sumv[i] = sumv[i-1];
    		}
    	}
    	ll cnt = 0;
    	for (int i = 1; i <= m; i ++){
    		ll l = B[i].w, r = B[i].v;
    		cnt += (sum[r]-sum[l-1]) * (sumv[r]-sumv[l-1]);
    	}
    	ans = min(ans, abs(s-cnt));
    	return cnt >= s;
    }
    int main(){
    	cin >> n >> m >> s;
    	for (int i = 1; i <= n; i ++) cin >> A[i].w >> A[i].v;
    	for (int i = 1; i <= m; i ++) cin >> B[i].w >> B[i].v;
    	ll l = 0, r = 1e6+2;
    	while(l < r){
    		ll mid = l + r + 1>> 1;
    		if(check(mid)) l = mid;
    		else r = mid - 1;
    	}
    	cout << ans;
    	return 0;
    }
    
    • 1

    信息

    ID
    4359
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    (无)
    递交数
    14
    已通过
    5
    上传者