Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has nn positions to install lamps, they correspond to the integer numbers from 00 to n−1n−1 on the OX axis. However, some positions are blocked and no post lamp can be placed there.
There are post lamps of different types which differ only by their power. When placed in position xx, post lamp of power ll illuminates the segment [x;x+l][x;x+l]. The power of each post lamp is always a positive integer number.
The post lamp shop provides an infinite amount of lamps of each type from power 11 to power kk. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power ll cost alal each.
What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0;n][0;n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 33 in position n−1n−1 (even though its illumination zone doesn't completely belong to segment [0;n][0;n]).
The first line contains three integer numbers nn, mm and kk (1≤k≤n≤1061≤k≤n≤106, 0≤m≤n0≤m≤n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains mm integer numbers s1,s2,…,sms1,s2,…,sm (0≤s1<s2<…sm<n0≤s1<s2<…sm<n) — the blocked positions.
The third line contains kk integer numbers a1,a2,…,aka1,a2,…,ak (1≤ai≤1061≤ai≤106) — the costs of the post lamps.
Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0;n][0;n] of the street.
If illumintaing the entire segment [0;n][0;n] is impossible, print -1.
6 2 3 1 3 1 2 3
6
4 3 4 1 2 3 1 10 100 1000
1000
5 1 5 0 3 3 3 3 3
-1
7 4 3 2 4 5 6 3 14 15
-1
题解:
n/1+n/2+n/3+...+n/n=n*logn
直接暴力即可。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+7;
bool vis[maxn];
int n,m,k,last[maxn];
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=m;i++)
{
int x;scanf("%d",&x);
vis[x]=1;
}
if(vis[0])
{
printf("-1\n");
return 0;
}
int la=0;
for(int i=1;i<=n;i++)//last保存要想照亮该点所能安装等的最大坐标
{
if(!vis[i])la=i;
last[i]=la;
}
ll ans=-1;
for(int i=1;i<=k;i++)
{
int x;scanf("%d",&x);
ll sum=0;
for(int j=0;j<n; )
{
sum+=x;
int id;
if(j+i>n)id=n;
else id=last[i+j];
if(id<=j)
{
sum=-1;break;
}
j=id;
}
if(sum!=-1)
{
if(ans==-1)ans=sum;
else ans=min(ans,sum);
}
}
printf("%lld\n",ans);
return 0;
}