CodeForce 990 E. Post Lamps

E. Post Lamps
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 n1n−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 n1n−1 (even though its illumination zone doesn't completely belong to segment [0;n][0;n]).

Input

The first line contains three integer numbers nnmm and kk (1kn1061≤k≤n≤1060mn0≤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 (0s1<s2<sm<n0≤s1<s2<…sm<n) — the blocked positions.

The third line contains kk integer numbers a1,a2,,aka1,a2,…,ak (1ai1061≤ai≤106) — the costs of the post lamps.

Output

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.

Examples
input
Copy
6 2 3
1 3
1 2 3
output
Copy
6
input
Copy
4 3 4
1 2 3
1 10 100 1000
output
Copy
1000
input
Copy
5 1 5
0
3 3 3 3 3
output
Copy
-1
input
Copy
7 4 3
2 4 5 6
3 14 15
output
Copy
-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;
}

猜你喜欢

转载自blog.csdn.net/albertluf/article/details/80720846