NOIP2011 Improve group of intelligent quality Supervisor-silvern

Source: Internet
Author: User

Title 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. A 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 test results of this batch of minerals are the sum of the test values for each interval. namely: Y1+y2...+ym

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. Little T

Do not 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

Standard S, even if the absolute value of the s-y is minimal. Please help to find out the minimum value.

Input/output format

Input format:

Enter the file qc.in.

The first line contains three integer n,m,s, each representing 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, and the 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.

Output format:

The output file name is Qc.out.

The output has only one row and contains an integer that represents the minimum value you are seeking.

Input and Output Sample input example # #:
Sample # # of output:
10
Description

"Input and Output sample description"

When W is selected 4, the test values of three intervals are 20, 5, 0, and the test result of this batch of minerals is 25, which

The minimum difference between the standard value S is 10.

"Data Range"

For 10% of the 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.

You are so clever, you have to calculate yourself!

Although the topic is very long and troublesome, but read it is very simple

The range of W should be between 1-ore maximum weight, because the range is large, so the enumeration cannot be over.

Don't worry, there are two points.

Here is the code

1 //2011 Improve Group of intelligent quality Supervisor by Silern2#include <cstdio>3#include <iostream>4#include <algorithm>5#include <cmath>6 using namespacestd;7 intn,m;8 Long Longmx,s;9 Long Longans=10000000000000;Ten structst{ One     intA; A     intb; -}a[300000],rg[300000];//A- ore rg-range - Long Longsv[300000],sc[300000];//from 1 to [I] range: The value and number of ores with values greater than w and the Long LongSuintW) {//Calculate test results with W as parameter -     inti,j; - //sv[0]=0; - //sc[0]=0; +      for(i=1; i<=n;i++){ -sv[i]=sv[i-1]; +sc[i]=sc[i-1]; A         if(A[I].A&GT;=W) {sv[i]+=a[i].b;sc[i]++;} at     }  -     Long Longsm=0; -      for(i=1; i<=m;i++){ -sm+= (SV[RG[I].B]-SV[RG[I].A]) * (sc[rg[i].b]-sc[rg[i].a]);//(The range satisfies the condition ore value and) * (satisfies the condition ore quantity) -     } -     returnSM; in }  - intMain () { toscanf"%d%d%lld",&n,&m,&s); +     inti,j; -      for(i=1; i<=n;i++){ thescanf"%d%d",&a[i].a,&a[i].b); *         if(A[I].B&GT;MX) mx=a[i].b; $     }Panax Notoginseng      for(i=1; i<=m;i++) -scanf"%d%d", &rg[i].a,&rg[i].b), rg[i].a--; the     Long LongMi=1, Mid,res; +      while(mi<=MX) {//Two points for benchmark value W AMid= (MI+MX)/2; theres=SU (mid); +         if(res==s) {printf ("0");return 0;} -         if(ABS (RES-S) <ans) ans=abs (res-s); $         if(res>s) mi=mid+1; $         Elsemx=mid-1; -     } -printf"%lld", ans); the     return 0; -}

NOIP2011 Improve group of intelligent quality Supervisor-silvern

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.