Intelligent Quality Supervisor (Codevs 1138)

Source: Internet
Author: User

Title Description DescriptionSmall 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 of testing the mineral is: see figure if the test results of this batch of minerals and the given standard value s difference too much, 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. Enter a description Input Description

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 description Output Description

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

Sample input Sample Input

5 3 15
1 5
2 5
3 5
4 5
5 5
1 5
2 4
3 3

Sample output Sample Output

10

Data range and Tips Data Size & Hint

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.


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≤106,0 < s≤1012,1≤li≤ri≤n.

/*The binary w value, for each binary, deals with two prefixes and, respectively, the number and quality (satisfying the condition), calculates the Y value, compares with S ....*/#include<cstdio>#include<iostream>#include<cmath>#defineM 200010#defineINF 1000000000000LL#defineLL Long Longusing namespacestd; LL W[m],v[m],l[m],r[m],qian_v[m],qian_n[m],n,m,s,minn=INF;intCheckintx) {     for(intI=1; i<=n;i++) {Qian_n[i]=qian_n[i-1]; Qian_v[i]=qian_v[i-1]; if(w[i]>=x) {Qian_n[i]++; Qian_v[i]+=V[i]; }} LL tot=0;  for(intI=1; i<=m;i++) Tot+ = (qian_v[r[i]]-qian_v[l[i]-1]) * (qian_n[r[i]]-qian_n[l[i]-1]); if(ABS (TOT-S) <Minn) Minn=abs (tot-s); if(tot<=s)return 1; Else return 0;}intMain () {CIN>>n>>m>>s;  for(intI=1; i<=n;i++) Cin>>w[i]>>V[i];  for(intI=1; i<=m;i++) Cin>>l[i]>>R[i]; LL LL=0, rr=INF;  while(ll<=RR) {LL Mid= (LL+RR)/2; if(Check (mid)) rr=mid-1; ElseLl=mid+1; } cout<<Minn; return 0;}
View Code

Intelligent Quality Supervisor (Codevs 1138)

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.