Description Small T is a quality supervisor, recently responsible for testing the quality of a number of minerals. These minerals have n ores, numbered from 1 to N, each with its own weight of WI and Value VI. The process for testing minerals is:
1, given m interval [Li, Ri];
2, choose a parameter W;
3. For an interval [Li, Ri], calculate the ore's test value on this interval Yi:
The yi=σ1*σvj,σ loop variable is J, where J satisfies J∈[li,ri] and wj≥w, where J is the ore number.
The test results of this batch of minerals are the sum of the test values for each interval. The σyi,σ loop variable is i,1≤i≤m.
If the test results of this batch of minerals and the given standard value is too much difference, it is necessary to test another batch of minerals. Small t don't want to take time to test another batch of minerals, so he wants to adjust the value of the parameter w, so that the test results as close as possible to the standard value s, even if the absolute value of the s-y is minimal. Please help to find out the minimum value. Input format the first line contains three integers n, m,s, which represent the number of ores, the number of intervals, and the standard values. The next n lines, 2 integers per line, are separated by a space, and the i+1 line represents the weight of the I ore, WI and Value VI.
The next M line, representing the interval, 2 integers per line, separated by a space, i+n+1 line represents the two endpoint Li and ri for the interval [Li, RI]. Note: Different intervals may overlap or coincide with each other. The output format output has only one row and contains an integer that represents the minimum value you are seeking. Test Sample 1 input
5 3 15
1 5
2 5
3 5
4 5
5 5
1 5
2 4
3 3
Output
10
An explanation of the sample
When W is selected 4, the test value of three interval is 20, 5, 0, the test result of this batch of minerals is 25, at this time the difference with the standard value S is the minimum of 10.
Note for 10% of data, there are 1≤n, m≤10;
For 30% of the data, there are 1≤n, m≤500;
For 50% of the data, there are 1≤n, m≤5,000;
For 70% of the data, there are 1≤n, m≤10,000;
For 100% of data, there are 1≤n, m≤200,000,0 < WI, vi≤10^6,0 < s≤10^12,1≤li≤ri≤n.pay attention to the interval processing, each check will be counted again prefix and
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>using namespacestd;Const intMAXN =220005;structstone{Long LongW; Long Longv;};Long LongN,m,s,l[maxn],r[maxn],sum[maxn],sumv[maxn],all,ans =98765432112345L; STONE STONE[MAXN];voidinput () {CIN>>n>>m>>s; All=0; for(inti =1; I <= n;i++) {scanf ("%lld%lld",&stone[i].w,&stone[i].v); if(All < STONE[I].W) All =STONE[I].W; } for(inti =1; I <= m;i++) {scanf ("%lld%lld",&l[i],&R[i]); }}BOOLCheckLong Longt) {sum[0] = sumv[0] =0; for(inti =1; I <= n;i++){ if(STONE[I].W >=t) {Sumv[i]= sumv[i-1] +stone[i].v; Sum[i]= sum[i-1] +1; }Else{Sumv[i]= sumv[i-1]; Sum[i]= sum[i-1]; }} All=0; for(inti =1; I <= m;i++) { All+ = (Sumv[r[i])-sumv[l[i]-1]) * (Sum[r[i])-sum[l[i]-1]); } ans= MIN (ABS (All-s), ans); returnAll <s;}voidDiv () {Long LongLANs =0, rans =All,mans; while(LANs <=rans) {Mans= (LANs + rans) >>1; if(check (mans)) {rans= Mans-1; }Else{LANs= Mans +1; }} check (Mans+1); if(Mans >0) Check (mans-1); cout<<ans;}intMain () {input (); Div (); return 0;}View Code
NOIP1138, intelligent quality supervisor.