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)