P1843 Cow drying clothes

Source: Internet
Author: User

Main topic:

n pieces of clothing, each dress has the initial humidity, under normal circumstances each dress in a unit time humidity minus A, the cow has a hair dryer, unit time can make a piece of clothing more minus B, ask the fastest how long can dry all. (1≤ humidity, a,b≤500000, 1≤n≤500000)

Ideas:

Each unit of time pick the most wet blow, with heap optimization. A record time variable i, each heap top element-1, if the heap top element ≤i*a, stop. Note that the initial value of I is good.

1#include <queue>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cstdlib>6 7 using namespacestd;8 9 intn,a,b,ans=0;Tenpriority_queue<int>humidity; One  A intMain () - { -scanf"%d%d%d",&n,&a,&b); the      for(intI=1; i<=n;i++) -     { -         inttem; -scanf"%d",&tem); + Humidity.push (TEM); -     } +     intAa=0; A      while(Humidity.top () >aa) at     { -         inttem=humidity.top (); - Humidity.pop (); -tem-=b; - Humidity.push (TEM); -aa+=A; inans++; -     } toprintf"%d\n", ans); +     return 0; -}
View Code

P1843 Cow drying clothes

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.