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