Educational Codeforces Round 45 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 n positions to install lamps, they correspond to the integer numbers from 0 to n1 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 x, post lamp of power l illuminates the segment [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 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost al 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] 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 3 in position n1 (even though its illumination zone doesn't completely belong to segment [0;n]).

Input

The first line contains three integer numbers nnmm and k (1kn1060mn) — 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,,sm (0s1<s2<sm<n) — the blocked positions.

The third line contains kk integer numbers a1,a2,,ak (1ai106) — 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] of the street.

If illumintaing the entire segment [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

题目:有0,1, 2, n个点要装lamp,但其中有m个点不能装,给1-k种不懂亮度的lamp,他的范围就是(x, x+l),然后每种l有一个花费,问覆盖所有点的最小花费。

分析:贪心先看一下最大的连续的不能装lamp的长度,然后如果0位置不能装的话,就不能实现,然后从maxlen长度开始看最小值就可以啦。

代码:

#include<bits/stdc++.h>
#define ll long long
#define INF 1e18
using namespace std;
const int maxn = 1e6+7;
int n, m, k, s[maxn];
bool vis[maxn];
ll a[maxn];

int main()
{
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d%d%d", &n, &m, &k)) {
        memset(vis, 0, sizeof(vis));
        memset(s, 0, sizeof(s));

        while(m--) { int x; scanf("%d", &x); vis[x] = true; }

        for(int i = 1; i <= k; i++) scanf("%lld", &a[i]);

        if(vis[0]) { printf("-1\n"); continue; }

        int len = 0; ll ans = INF;
        for(int i = 0; i <= n;i++) {
                if(vis[i]) s[i] = s[i-1] + 1;
                else s[i] = 0;
                len = max(len, s[i]);
        }
        ans = INF;
        for(int i = len+1; i <= k; i++) {
            ll cnt = 0;
            for(int j = 0; j < n; j += i)
            {
                if(vis[j])j -= s[j];
                cnt++;
            }
            ans = min(ans, a[i]*cnt);
        }
        if(ans >= INF) printf("-1\n");
        else printf("%lld\n", ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_39792252/article/details/80661829