(Jizhong) 2222. Save the chicken (chicken)

(File IO): input: chicken.in output: chicken.out
time limit: 1000 ms space constraints: 262144 KB specific restrictions
Goto ProblemSet


Title Description
chicken had recently encountered a tricky business, often want to catch an eagle chicks. State intelligence agents probing by the chicken, the eagle were going to be attacked n n th, i i times to come for the first time t i ( 1 i n ) ti (1≤i≤n) second time.
King chicken country in order to protect the country's chicken chicks, chicken country decided to send the police (state-owned chicken infinite number of police) to patrol. The length of time of each police patrols are t t seconds. When the moment to attack the eagle must have at least x x policemen were able to withstand the Hawks attack. Also king sent police to two principles:
(1) each time only send a maximum of a police officer. In the first 0 0 every second and second 0 0 time seconds before the (state-owned chicken negative moment) can also be prepared to send police, but most can only be sent every time a police officer.
(2) delay 1 1 Miao patrol. The first i i second time to send the police in the first i + 1 i+1 to i + t i+t s patrol time.
To help save money king, please help calculate how many police officers need to send at least to ensure the country's chicken chicks will not be taken away by an eagle?


Input
Input of 2 rows.
The first 1 1 line of the input three integers n t x n,t,x , respectively eagle total number of attacks, the length of time of each police patrol, and at some point be able to withstand a minimum number of police officers live eagle attacks.
The first 2 2 -line n n positive integers strictly ascending order t i ( 1 i n ) ti (1≤i≤n) , represents t i ti s time the Eagles will attack.

Output
Output 1 1 line an integer representing the total number of police dispatch at least need to be able to withstand the Eagles n n times the attack, if there can not resist the eagle attacks, output 1 “-1” (without the quotes).


Sample input
Input1:
. 3. 3. 3
2. 4. 3

Input2:
1 2 3
3

Sample output
Output1:
. 5

Output2:
-1


Data range limit
Here Insert Picture Description


Tip
Sample1:
Sample 1 1 , the eagle to attack 3 3 times, respectively, in the first 2 3 4 2,3,4 a seconds time, police patrol time for each 3 3 seconds when the Eagles to attack must be able to withstand at least three policemen eagle attacks. First of all can be the first 1 0 1 -1,0,1 second Three moments were sent a police officer, first against the Eagles 2 2 raid seconds time, and then the second time in seconds to send a police officer, along with the first 0 1 0,1 Miao two moments dispatch of police (first this time 1 -1 every second and has dispatched police break) can withstand the Eagles first 3 3 attacks every second and finally first 3 3 every second and send a police officer, along with the first 1 2 1,2 Miao two moments dispatch of police (first this time 0 0 every second and dispatched police have rested) will be the first against the Eagles 4 4 raid seconds of time, so at least need to send 5 5 policemen.

Sample2:
Sample 2 2 , the eagle to attack 1 1 times in the first 3 3 every second and, each time the police patrol was 2 2 seconds but have at least when Eagles to attack 3 3 police officers in order to resist the Hawks attack, according to the principle king sent the police, can not be achieved against the Eagles tasks, output 1 “-1”


Problem-solving ideas
violence. First enumeration, if not enough police to patrol the current point, and then as close as possible to put enough.


Code

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
const int INF=10000;
int n,t,x,ans,a,b[100010],s;
int main(){
   freopen("chicken.in","r",stdin);
   freopen("chicken.out","w",stdout);
    scanf("%d%d%d",&n,&t,&x);
    if(x>t)
    {
        printf("-1");
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        s=0;
        for(int j=a-1;j>=a-t;j--)
            if(b[j+INF])
                s++;
        if(s<x)
            for(int j=a-1;j>=a-t;j--)
            {
                if(!b[j+INF])
                {
                    b[j+INF]=1;
                    ans++;
                    s++;
                    if(s==x)
                    break;
                }
            } 
    }
    printf("%d",ans);
}
Published 119 original articles · won praise 8 · views 4904

Guess you like

Origin blog.csdn.net/kejin2019/article/details/105125517