codeforce-810b Summer sell-off (struct sort)

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/810/B

Known n days, the availability and demand for the first day is known, given an F, can be selected in the N days of the F-day promotion to double the supply volume.

Q The total sales volume after n days is doubled after the number of deliveries in F days.

Idea: first for each day to calculate the normal sales x1 = min (supply volume, demand), and then calculate each day after the sale of sales x2 = min (supply volume, demand).

Sort the x2-x1, find out the sales increase after the sale of the biggest F day, the normal analog output can be.

Structure:

struct node

{

Long Long supply volume, sales volume, normal sales, sales promotion;

Normal sales = min (supply quantity, demand);

Sales volume = min (Supply volume *, demand);

} goods [100005];

/* The test data on CF has more than 100 groups. */

1#include <bits/stdc++.h>2 using namespacestd;3 structnode4 {5     intk,l,x1,x2;6}s[100050];7 intCMP (node A,node b)8 {9     returnA.x2>b.x2;Ten } One intMain () A { -     intn,f; -Cin>>n>>F; the      for(intI=0; i<n;i++) -     { -Cin>>s[i].k>>S[I].L; -S[i].x1=s[i].k>=s[i].l?S[I].L:S[I].K; +s[i].x2=s[i].k*2>=s[i].l?s[i].l:s[i].k*2; -s[i].x2-=s[i].x1; +     } ASort (s,s+n,cmp); at     Long Longans=0; -      for(intI=0; i<n;i++) -     { -         if(i<f) ans+=s[i].k*2>=s[i].l?s[i].l:s[i].k*2; -         Elseans+=s[i].x1; -     } incout<<ans<<Endl; -     return 0; to}

codeforce-810b Summer sell-off (struct sort)

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.