Title Link: Http://codeforces.com/contest/810/problem/B
Test instructions: Given the number of days and the number of days the goods can be doubled, every day there is a certain amount of goods and the number of customers, ask how the goods can sell the most (the day before the goods will not be left to the next, each customer can only buy one goods).
Simple greedy question, greedy strategy is: if two times the volume of goods sold out more, choose twice times, or choose one times.
The amount of goods that can be sold on that day: min (quantity of goods, number of customers). And then sort it out according to the structure, OK.
1#include <iostream>2#include <algorithm>3 using namespacestd;4 5 Const intn=1e5+Ten;6 7 structtnt{8 Long LongK;9 Long Longl;Ten }t[n]; One A BOOLCMP (TnT a,tnt b) { - return(Min (2*A.K,A.L)-min (A.K,A.L)) > (min (2*B.K,B.L)-min (B.K,B.L)); - } the - intMain () { - Long Longn,f,res=0; -Cin>>n>>F; + for(intI=0; i<n;i++){ -Cin>>t[i].k>>T[I].L; + } ASort (t,t+n,cmp); at for(intI=0; i<n;i++){ - if(f>0) {Res+=min (2*T[I].K,T[I].L); f--;} - Elseres+=min (t[i].k,t[i].l); - } -cout<<res<<Endl; - return 0; in}
Codeforces Round #415 (Div. 2) B. Summer Sell-off (greedy + struct sort)