CodeForce 990 E. Post Lamps

本文介绍了一种路灯布局优化算法,旨在解决如何在街道上有效布置不同功率的路灯以覆盖整个街区的问题。考虑到某些位置可能不可用,算法需找出最低成本方案来确保整个街区被照亮。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值