Codeforces Round #415 (Div. 2) B. Summer Sell-off (greedy + struct sort)

Source: Internet
Author: User

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)

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.