#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
struct node
{
int x;
int y;
}q[3010];
int a[3001];
int n,m,k;
int main()
{
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(a,0,sizeof(a));
memset(q,0,sizeof(q));
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
if(m<k)
{
printf("-1\n");
continue;
}
int kk = m;
int sum = 0;
int flag = 0;
for(int i=0;i<n;i++)
{
if(i == 0)
{
sum = k;
for(int j=a[i]-k;j<a[i];j++)
{
q[j].y = 1;
}
for(int j=a[i];j<a[i]+m;j++)
{
q[j].x = kk;
kk--;
}
}
else
{
if(q[a[i]].x < k)
{
//printf("q[%d].x = %d\n",a[i],q[a[i]].x);
int cnt = k - q[a[i]].x;
sum += cnt;
for(int j=a[i]-cnt;j<a[i];j++)
{
if(q[j].y == 1)
{
flag = 1;
break;
}
q[j].y = 1;
for(int v=j+1;v<m+j+1;v++)
{
q[v].x++;
}
}
}
}
if(flag == 1)
{
break;
}
}
if(flag == 1)
{
printf("-1\n");
}
else
{
printf("%d\n",sum);
}
}
return 0;
}
标签:memset,EOF,int,d%,Codeforces,288,sizeof,include,Round
From: https://blog.51cto.com/u_14834528/7626440