CF 460C Present [DP + idea], 460cdp

Source: Internet
Author: User

CF 460C Present [DP + idea], 460cdp

Give you the height of n flowers. For m days, you can pour continuously w flowers every day. Once a day, each flower increases by 1 unit height.

Find the maximum number of shorter flowers in m days.

 

The maximum and minimum problems can be solved using two points.

 

First, we can get the shortest height of all flowers, that is, the lower bound of the answer. Pouring m days for this flower is the upper bound of the answer.

Then, the answers are enumerated in two parts to check validity.

 

How to check legitimacy

 

We use an array to record the need [I] representation.The number of times the I point needs to be poured (the interval starting from I point)

We use another variable has for maintenance.Number of times that I point has been poured (the number of times that I point has been poured in the watering range before I)

Dynamically maintain these two values.

If not, return false if the need [I] prefix and m days are greater;

Otherwise return true;

 

#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>using namespace std;const int NN=111111;int n,m,w;int need[NN];int f[NN];bool can(int s){int a=0;int b=m;for(int i=1;i<=n;i++){if(i>=w)a-=need[i-w];need[i]=max((int)0,s-a-f[i]);a+=need[i];b-=need[i];if(b<0)return false;}return true;}int main(){#ifndef ONLINE_JUDGEfreopen("G:/in.txt","r",stdin);//freopen("G:/myout.txt","w",stdout);#endifcin>>n>>m>>w;int minn=(1<<30);for(int i=1;i<=n;i++){cin>>f[i];minn=min(f[i],minn);}int maxn=minn+m;int mid=(minn+maxn)/2+1;while(minn<maxn){if(can(mid)){minn=mid;}else{maxn=mid-1;}mid=(minn+maxn)/2+1;}cout<<minn<<endl;}


 


What are the basic steps of the cube CFDP method?

Cfop is a third-level advanced gameplay. There are no basic steps and layer-first method (the seven-step method is similar in principle) there are 119 formulas, of which the 41 formulas in the second step f2l are difficult, you can remember them completely or you can understand them. You can also call cfop the four-step method. The first step is the cross. The second step is to restore the first two layers. The third step is the first step. shift to restore cube

The relation and meaning of TG-CF-IS-TF-CON-DP-TRX-TX-RX-TS in Ericsson BSC

L

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.