text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; long long BIG = 1e14; vector<int> block; vector<int> street; vector<int> dp; vector<int> price; int main() { ios::sync_with_stdio(0); int n; int m; int k; cin >> n >> m >> k; block.resize(m, 0); street.resize(n + 1, 0); dp.resize(n + 1, -1); price.resize(k); for (int i = 0; i < m; i++) { cin >> block[i]; street[block[i]] = 1; } for (int i = 1; i <= n; i++) { if (street[i] == 0) { dp[i] = i; } else { dp[i] = dp[i - 1]; } } for (int i = 0; i < k; i++) { cin >> price[i]; } long long ans = BIG; if (!street[0]) { for (int i = 1; i <= k; i++) { int cur = 1; int x = 0; while (x + i < n) { cur++; if (x < dp[x + i]) { x = dp[x + i]; } else { cur = 0; break; } } if (cur) { if (ans > (long long)cur * price[i - 1]) { ans = (long long)cur * price[i - 1]; } } } } if (ans == BIG) { cout << -1 << endl; } else { cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long fpow(long long n, long long k, int p = MOD) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> void setmin(T& a, T val) { if (a > val) a = val; } template <class T> void setmax(T& a, T val) { if (a < val) a = val; } void addmod(int& a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } void submod(int& a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } const int N = 1000005; int pre[N], cost[N], block[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= m; i++) { int x; cin >> x; block[x] = 1; } if (block[0]) pre[0] = -1; else pre[0] = 0; for (int i = 1; i <= N; i++) { if (!block[i]) pre[i] = i; else pre[i] = pre[i - 1]; } for (int i = 1; i <= k; i++) cin >> cost[i]; long long ans = LINF; for (int i = 1; i <= k; i++) { int pos = 0, cnt = 0, lst = -1; while (pos < n) { if (pre[pos] <= lst) { cnt = -1; break; } cnt++; lst = pre[pos]; pos = lst + i; } if (cnt != -1) ans = min(ans, (long long)cnt * cost[i]); } if (ans != LINF) cout << ans << "\n"; else cout << "-1\n"; return 0; }
#include <bits/stdc++.h> using namespace std; 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++) { if (!vis[i]) la = i; last[i] = la; } long long ans = -1; for (int i = 1; i <= k; i++) { int x; scanf("%d", &x); long long 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; }
#include <bits/stdc++.h> using namespace std; const long long INF = 100000000000000000; long long s[1000005]; long long l[1000005]; int main() { long long n, m, k; cin >> n >> m >> k; for (int i = 0; i < m; i++) scanf("%lld", &s[i]); if (m > 0 && s[0] == 0) { cout << -1 << endl; return 0; } for (int i = 0; i < n; i++) l[i] = i; for (int i = 0; i < m; i++) l[s[i]] = l[s[i] - 1]; long long ans = INF; for (int i = 1; i <= k; i++) { long long c = 0; long long j = 0; bool f = true; while (true) { if (j + i >= n) { c++; break; } if (l[j + i] == j) { f = false; break; } j = l[j + i]; c++; } long long a; scanf("%lld", &a); if (f) ans = min(ans, c * a); } if (ans == INF) cout << -1 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int f[1000005], a[1000005]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; i++) { int x; scanf("%d", &x); f[x] = 1; } for (int i = 1; i <= k; i++) scanf("%d", &a[i]); if (f[0]) { puts("-1"); return 0; } for (int i = 0; i <= n; i++) f[i] = f[i] ? f[i - 1] : i; int lim = 0; for (int i = 0; i <= n; i++) lim = max(lim, i == n ? i - f[i] : i - f[i] + 1); if (k < lim) { puts("-1"); return 0; } long long ans = 1ll << 60; for (int i = lim; i <= k; i++) { long long tmp = 0; int cur = 0; for (;; cur = f[cur + i]) { tmp += a[i]; if (cur + i >= n) break; } ans = min(ans, tmp); } printf("%I64d\n", ans); }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; const int M = 1e6 + 500; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int BASE = 31337; const int LOG = 18; const int OFF = (1 << LOG); const double EPS = 1e-9; const double PI = 3.1415926535; int blok[M], n, bio[M], pref[M], lft[M], q, k; int get(int l, int r) { if (l <= 0) return pref[r]; return pref[r] - pref[l - 1]; } int check(int x) { int sol = 0; for (int i = 0; i < n; i++) { if (blok[i]) { if (lft[i] <= i - x) { return -1; } else { i = lft[i] + x - 1; sol++; } } else { i += x - 1; sol++; } } return sol; } int main() { scanf("%d%d%d", &n, &q, &k); for (int i = 0; i < q; i++) { int x; scanf("%d", &x); blok[x] = 1; } if (blok[0]) lft[0] = -INF; else lft[0] = 0; for (int i = 1; i < n; i++) { if (!blok[i]) lft[i] = i; else lft[i] = lft[i - 1]; } long long fin = (long long)INF * INF; for (int i = 1; i <= k; i++) { int x; scanf("%d", &x); int y = check(i); if (y == -1) continue; fin = min(fin, (long long)x * y); } if (fin == (long long)INF * INF) printf("-1\n"); else printf("%I64d\n", fin); return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INF64 = 1e18; const int N = 1000 * 1000 + 13; int n, m, k; bool pos[N]; int lst[N], s[N], a[N]; int get(int l) { int r = 0, i = -1, res = 0; while (r < n) { if (lst[r] <= i) return INF; i = lst[r]; r = lst[r] + l; ++res; } return res; } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < int(m); i++) scanf("%d", &s[i]); for (int i = 0; i < int(k); i++) scanf("%d", &a[i]); for (int i = 0; i < int(n); i++) pos[i] = true; for (int i = 0; i < int(m); i++) pos[s[i]] = false; for (int i = 0; i < int(n); i++) { if (pos[i]) lst[i] = i; else if (i) lst[i] = lst[i - 1]; else lst[i] = -1; } long long ans = INF64; for (int i = 0; i < int(k); i++) { long long t = get(i + 1); if (t != INF) ans = min(ans, a[i] * t); } printf("%lld\n", ans == INF64 ? -1 : ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long modulo(long long base, long long exponent, long long modulus); long long choose(long long n, long long k); long long inverse(long long a, long long m); void build() {} vector<long long> visit(1000010); vector<long long> freee(1000010); int main() { build(); long long n, m, k; scanf("%lld %lld %lld", &n, &m, &k); vector<long long> blocked(m); for (int i = 0; i < m; i++) { scanf("%lld", &blocked[i]); visit[blocked[i]] = 1; } vector<long long> price(k + 1); for (int i = 1; i <= k; i++) scanf("%lld", &price[i]); long long mini = 0; long long temp = 0; for (int i = 0; i < n; i++) { if (visit[i] == 1) { temp++; } else { temp = 0; } mini = max(mini, temp); } mini++; if (visit[0] == 1 || mini > k) { cout << -1 << endl; return 0; } long long lastfree = 0; for (int i = 0; i < n; i++) { if (visit[i] == 1) { freee[i] = lastfree; } else { lastfree = i; } } long long ans = LONG_LONG_MAX; for (int len = mini; len <= k; len++) { long long lans = 0; long long i = 0; long long power = len; long long cost = price[power]; lans += cost; i += power; while (i < n) { if (visit[i] == 1) { i = freee[i]; } if (i >= n) break; lans += cost; i += power; } ans = min(ans, lans); } cout << ans << endl; return 0; } long long modulo(long long base, long long exponent, long long modulus) { if (modulus == 1) return 0; long long result = 1; base = base % modulus; while (exponent > 0) { if (exponent % 2 == 1) { result = (result * base) % modulus; } exponent = exponent >> 1; base = (base * base) % modulus; } return result; } long long choose(long long n, long long k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } void EE(long long a, long long b, long long &co1, long long &co2) { if (a % b == 0) { co1 = 0; co2 = 1; return; } EE(b, a % b, co1, co2); long long temp = co1; co1 = co2; co2 = temp - co2 * (a / b); } long long inverse(long long a, long long m) { long long x, y; EE(a, m, x, y); if (x < 0) x += m; return x; }
#include <bits/stdc++.h> using namespace std; int n, m, k; int s[1000005]; int f[1000005]; int a[1000005]; long long inf = 0x3f3f3f3f3f3f3f3f; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < m; i++) { scanf("%d", &s[i]); f[s[i]] = 1; } for (int i = 1; i <= k; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n; i++) if (f[i]) f[i] += f[i - 1]; long long ans = inf; for (int i = 1; i <= k; i++) { long long cnt = 0; for (int j = 0; j < n; j += i, cnt++) { if (f[j]) { if (f[j] >= i || j - f[j] < 0) { cnt = inf; break; } j -= f[j]; } } if (cnt == inf) continue; ans = min(ans, cnt * a[i]); } if (ans == inf) return !printf("-1\n"); printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, m, k, f[N], a[N], mx, last[N]; long long ans = 1e18; int main() { cin >> n >> m >> k; for (int i = 0, x; i < m; ++i) { scanf("%d", &x); f[x] = 1; } for (int i = 1; i <= k; ++i) { scanf("%d", a + i); } int sum = 0, l = 0; for (int i = 0; i < n; ++i) { sum += f[i]; mx = max(sum, mx); if (f[i] == 0) sum = 0, l = i; else last[i] = l; } if (mx >= k || f[0]) return puts("-1"), 0; for (int i = mx + 1; i <= k; ++i) { long long cost = 0; for (int j = 0; j < n; j += i) { cost += (long long)a[i]; if (f[j]) j = last[j]; } ans = min(ans, cost); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; const int N = 1000005; const long long MOD = 1e9 + 7; int dX[] = {0, 0, 1, -1}; int dY[] = {1, -1, 0, 0}; int n, m, k, cst[N], nearest[N]; long long ans; bool block[N]; int calc(int S) { int cur = 0, ret = 0; while (cur < n) { ret++; if (cur + S >= n) return ret; if (cur == nearest[cur + S]) return 0; cur = nearest[cur + S]; } return ret; } int main() { scanf("%d", &n); scanf("%d", &m); scanf("%d", &k); int x; for (int i = 0; i <= n; ++i) nearest[i] = i; for (int i = 0; i < m; ++i) { scanf("%d", &x); if (x == 0) return puts("-1"); nearest[x] = nearest[x - 1]; } for (int i = 1; i <= k; ++i) scanf("%d", &cst[i]); ans = 4000000000000000100; for (int i = 1; i <= k; ++i) { int cnt = calc(i); if (cnt) ans = min(ans, cnt * 1LL * cst[i]); } if (ans == 4000000000000000100) puts("-1"); else printf("%lld", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 1010; ; int n, k, m; int lst[maxn]; bool ok[maxn]; int a[maxn]; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; i++) { int x; scanf("%d", &x); ok[x] = 1; } if (ok[0]) { puts("-1"); return 0; } int tmp = 0; for (int i = 1; i <= n; i++) { if (!ok[i]) tmp = i; lst[i] = tmp; } long long ans = 1LL * maxn * maxn; bool ok = 0; for (int i = 1; i <= k; i++) { int p; scanf("%d", &p); int nw = 0, num = 1; bool flag = 1; while (nw + i < n) { num++; if (lst[nw + i] <= nw) { flag = 0; break; } nw = lst[nw + i]; } if (flag) { ok = 1; ans = min(ans, 1LL * num * p); } } if (!ok) { puts("-1"); return 0; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2000000 + 10; int n, m, K; int a[maxn]; int maxlen; bool block[maxn]; int last[maxn]; inline void init() { scanf("%d%d%d", &n, &m, &K); for (int i = 1, p; i <= m; i++) { scanf("%d", &p); block[p] = 1; } for (int i = 1; i <= K; i++) scanf("%d", &a[i]); int cnt = block[0]; int pos = block[0] ? -1 : 0; for (int i = 1; i <= n; i++) { if (block[i]) cnt++; else { maxlen = max(maxlen, cnt); cnt = 0; pos = i; } last[i] = pos; } for (int i = 1; i <= K; i++) last[n + i] = n; } inline void exec() { if (block[0] || maxlen >= K) { puts("-1"); return; } long long ans = 1e18; for (int len = 1; len <= K; len++) { int pos = 0; long long res = 0; while (pos < n) { res += a[len]; if (last[pos + len] <= pos) break; pos += len; pos = last[pos]; } if (pos >= n) ans = min(ans, res); } printf("%lld\n", ans); } int main() { if (fopen("F.in", "r") != NULL) { freopen("F.in", "r", stdin); freopen("F.out", "w", stdout); } init(); exec(); return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000000000; const int mod = 1000000007; int n, m, k; int s[1000010]; long long a[1000010]; bool pos[1000010]; int lst[1000010]; long long get(int l) { int r = 0; int i = -1; long long res = 0; while (r < n) { if (lst[r] <= i) { return inf; } i = lst[r]; r = lst[r] + l; ++res; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; for (int i = 0; i < m; i++) { cin >> s[i]; } for (int i = 0; i < k; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { pos[i] = true; } for (int i = 0; i < m; i++) { pos[s[i]] = false; } for (int i = 0; i < n; i++) { if (pos[i]) { lst[i] = i; } else if (i) { lst[i] = lst[i - 1]; } else lst[i] = -1; } long long ans = inf; for (int i = 0; i < k; i++) { long long t = get(i + 1); if (t != inf) { ans = min(ans, a[i] * t); } } if (ans == inf) { ans = -1; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << '(' << p.first << ", " << p.second << ')'; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { long long l = v.size(); for (long long i = 0; i < l - 1; i++) out << v[i] << ' '; if (l > 0) out << v[l - 1]; return out; } template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << "\n"; } template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; trace(comma + 1, args...); } long long n, m, k; long long path[2000000]; long long cost[2000000]; long long near[2000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> k; for (long long i = 0; i < m; i++) { long long temp; cin >> temp; path[temp] = 1; } for (long long i = 1; i <= k; i++) { cin >> cost[i]; } long long max_block = 0; long long c = 0; for (long long i = 0; i < n; i++) { if (path[i] == 1) { c++; max_block = max(c, max_block); } else { c = 0; } } if (path[0] == 1 or max_block >= k) { cout << -1 << "\n"; return 0; } long long t = 0; for (long long i = 1; i < n; i++) { if (path[i] == 1) { near[i] = t; } else { t = i; } } c = 0; long long min_cost = 1000000000000000001; for (long long i = max_block + 1; i <= k; i++) { for (long long j = 0; j < n; j += i) { c += cost[i]; if (path[j] == 1) { j = near[j]; } } min_cost = min(min_cost, c); c = 0; } cout << min_cost << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; class Solution { public: long long minCost(int n, vector<int>& blocks, vector<int>& prices) { int m = prices.size(); vector<int> pre(n, 0); iota(pre.begin(), pre.end(), 0); if (!blocks.empty() && blocks[0] == 0) { return -1; } for (int i = 0, j = 0; i < n && j < blocks.size(); ++i) { if (i == blocks[j]) { pre[i] = pre[i - 1]; ++j; } } int minL = 0; for (int i = 0; i < blocks.size(); ++i) { int cnt = 1; while (i + 1 < blocks.size() && blocks[i + 1] == blocks[i] + 1) { ++i; ++cnt; } minL = max(minL, cnt); } long long res = LLONG_MAX; int minPrice = INT_MAX; for (int l = m; l > minL; --l) { if (minPrice < prices[l - 1]) { continue; } minPrice = prices[l - 1]; int cnt = 0; int p = 0; while (p < n) { p += l; ++cnt; if (p < n && pre[p] != p) { p = pre[p]; } } res = min(res, 1LL * cnt * prices[l - 1]); } return res == LLONG_MAX ? -1 : res; } }; int main(int argc, char** argv) { int n, m, k; scanf("%d%d%d", &n, &m, &k); vector<int> blocks; blocks.reserve(m); for (int i = 0, b = 0; i < m; ++i) { scanf("%d", &b); blocks.push_back(b); } vector<int> prices; prices.reserve(k); for (int i = 0, p = 0; i < k; ++i) { scanf("%d", &p); prices.push_back(p); } Solution sol; printf("%s\n", to_string(sol.minCost(n, blocks, prices)).c_str()); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; bool block[N]; int pre[N]; int n, m, k; long long cnt = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 0; i < m; i++) { int x; cin >> x; block[x] = true; } if (block[0]) return cout << -1, 0; for (int i = 0; i < n; i++) { if (!block[i]) pre[i] = i; else pre[i] = pre[i - 1]; } for (int i = 1; i <= k; i++) { int cost, tmp = 0; cin >> cost; for (int j = 0;; j = pre[j + i]) { tmp++; if (j + i >= n) { cnt = min(cnt, 1LL * tmp * cost); break; } if (pre[j + i] == j) break; } } return cout << ((cnt == 1e18) ? -1 : cnt), 0; }
#include <bits/stdc++.h> using namespace std; using namespace std; inline int read() { char ch; bool sign = 0; int res = 0; while (!isdigit(ch = getchar())) if (ch == '-') sign = 1; while (isdigit(ch)) res = res * 10 + (ch ^ 48), ch = getchar(); if (sign) return -res; else return res; } const int maxn = 1000000 + 10; const long long MAXN = 5000000 + 10; const long long inf = 1e18; const int MAXM = 3; const int maxm = 1000 + 10; const long long MOD[] = {469762049, 998244353, 1004535809, 1000000007}; const long long mod = 998244353; const int apsz = 26; const int block = 430; int vis[maxn], n, k, m; int a[maxn]; int can[maxn]; inline long long solve() { if (vis[0] == 1) return -1; int maxlen = 1; for (int l = 0; l < n;) { for (; l < n && vis[l] == 0;) ++l; int r = l; if (l >= n) break; for (; r < n && vis[r] == 1;) { can[r] = l - 1; ++r; } int now = r - l + 1; maxlen = max(maxlen, now); l = r; } long long ans = inf; for (int i = maxlen; i <= k; ++i) { long long tmp = 0; int j; for (j = 0; j < n;) { if (vis[j] == 0) { tmp += a[i]; j += i; } else { j = can[j]; tmp += a[i]; j += i; } } ans = min(ans, tmp); } if (ans == inf) ans = -1; return ans; } int main(void) { scanf("%d%d%d", &n, &m, &k); for (auto i = (1); i <= (m); ++i) { int x; scanf("%d", &(x)); vis[x] = 1; } for (auto i = (1); i <= (k); ++i) scanf("%d", &(a[i])); printf("%lld\n", solve()); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; int block[m + 1], power[k + 1]; int lst[2000100]; for (int i = 1; i <= m; i++) { cin >> block[i]; } for (int i = 1; i <= k; i++) { cin >> power[i]; } if (m && block[1] == 0) { cout << "-1\n"; return 0; } long long ans = MAXN; for (int i = 0; i < 2000100; i++) { lst[i] = i; } for (int i = 1; i <= m; i++) { lst[block[i]] = lst[block[i] - 1]; } for (int i = 1; i <= k; i++) { long long sum = 0; int now = 0, pre = -1; while (now < n) { if (now <= pre) break; sum += power[i]; pre = now; now = lst[now + i]; } if (now < n) continue; ans = min(ans, sum); } if (ans == MAXN) { cout << "-1\n"; } else { cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const long long inf = 1e18; int n, m, k, lt[maxn], cost[maxn]; bool vis[maxn]; long long solve(int v) { int now = 0; long long cnt = 0; while (true) { cnt++; now += v; if (now >= n) return cnt; if (lt[now] == now - v) return -1; now = lt[now]; } } int main() { int i, j, x; long long ans, val; while (scanf("%d%d%d", &n, &m, &k) != EOF) { memset(vis, false, sizeof(vis)); for (i = 1; i <= m; i++) { scanf("%d", &x); vis[x] = true; } for (i = 1; i <= k; i++) scanf("%d", &cost[i]); if (vis[0]) { printf("-1\n"); continue; } for (i = 0; i < n; i++) { if (vis[i]) lt[i] = lt[i - 1]; else lt[i] = i; } ans = inf; for (i = 1; i <= k; i++) { val = solve(i); if (val != -1) ans = min(ans, val * cost[i]); } if (ans == inf) printf("-1\n"); else printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long fpow(long long n, long long k, int p = MOD) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> void setmin(T& a, T val) { if (a > val) a = val; } template <class T> void setmax(T& a, T val) { if (a < val) a = val; } void addmod(int& a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } void submod(int& a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } const int N = 1000005; int pre[N], cost[N], block[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= m; i++) { int x; cin >> x; block[x] = 1; } if (block[0]) pre[0] = -1; else pre[0] = 0; for (int i = 1; i <= n; i++) { if (!block[i]) pre[i] = i; else pre[i] = pre[i - 1]; } for (int i = 1; i <= k; i++) cin >> cost[i]; long long ans = LINF; for (int i = 1; i <= k; i++) { int pos = 0, cnt = 0, lst = -1; while (pos < n) { if (pre[pos] <= lst) { cnt = -1; break; } cnt++; lst = pre[pos]; pos = lst + i; } if (cnt != -1) ans = min(ans, (long long)cnt * cost[i]); } if (ans != LINF) cout << ans << "\n"; else cout << "-1\n"; return 0; }
#include <bits/stdc++.h> const long long N = 1000006; using namespace std; const long long MOD = 1000000007LL; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T power(T x, T y, long long m = MOD) { T ans = 1; while (y > 0) { if (y & 1LL) ans = (ans * x) % m; y >>= 1LL; x = (x * x) % m; } return ans % m; } long long cost[N], ch[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, k; cin >> n >> m >> k; for (long long(i) = (0); i < (m); i++) { long long x; cin >> x; ch[x] = 1; } for (long long(i) = (0); i < (k); i++) cin >> cost[i]; vector<long long> v; for (long long(i) = (0); i < (n); i++) { if (!ch[i]) v.emplace_back(i); } long long ans = 1000111000111000111LL; for (long long i = 1; i <= k; i++) { long long tc = 0; bool f = 0; for (long long j = 0; j < n; j += i) { if (!ch[j]) { tc += cost[i - 1]; } else { auto idx = lower_bound(v.begin(), v.end(), j); if (idx == v.begin()) { f = 1; break; } --idx; if (abs(*idx - j) >= i) { f = 1; break; } tc += cost[i - 1]; j = *idx; } } if (f) continue; ans = min(ans, tc); } if (ans == 1000111000111000111LL) cout << "-1"; else cout << ans; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long inf = 1e18; int n, m, k; int c[N]; int a[N]; int v[N]; int get(int k) { int p = 0, s = 0; while (p < n) { int ls = v[p]; if (ls + k <= p) return -1; p = ls + k; s++; } return s; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m >> k; for (int i = 0; i < (m); i++) { int x; cin >> x; a[x] = 1; } for (int i = (1); i <= (k); i++) cin >> c[i]; if (a[0]) { cout << "-1\n"; return 0; } for (int i = 1; i < n; i++) { v[i] = v[i - 1]; if (!a[i]) v[i] = i; } long long ans = inf; for (int i = (1); i <= (k); i++) { int t = get(i); if (t != -1) { ans = min(ans, 1LL * c[i] * t); } } if (ans == inf) ans = -1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n, m, k; int s[1000005], a[1000005]; int bf[2000005]; long long ans = 0x7fffffffffffffff; int main() { ios::sync_with_stdio(0); cin >> n >> m >> k; for (int i = 1; i <= n * 2; i++) { bf[i] = i; } for (int i = 1; i <= m; i++) { cin >> s[i]; bf[s[i]] = bf[s[i] - 1]; if (s[i] == 0 || s[i] - bf[s[i]] > k) { cout << -1; return 0; } } for (int i = 1; i <= k; i++) { cin >> a[i]; long long rem = 0, id = 0; for (id = 0; id < n && bf[id + i] != id; id = bf[id + i]) { rem += a[i]; } if (id >= n) { ans = min(ans, rem); } } if (ans == 0x7fffffffffffffff) { cout << -1; return 0; } cout << ans; return 0; }
#include <bits/stdc++.h> int dr[] = {2, 2, -2, -2, 1, -1, 1, -1}; int dc[] = {1, -1, 1, -1, 2, 2, -2, -2}; int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1}; int dr2[] = {0, 0, 1, -1}; int dc2[] = {1, -1, 0, 0}; using namespace std; long long mark[1000005], a[1000005]; int main() { long long n, m, k, i, j, x; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); while (cin >> n >> m >> k) { for (i = 0; i < n; i++) mark[i] = i; for (i = 1; i <= m; i++) { cin >> x; mark[x] = -1; } for (i = 1; i <= k; i++) cin >> a[i]; if (mark[0] == -1) { cout << "-1" << endl; continue; } for (i = 1; i < n; i++) if (mark[i] == -1) mark[i] = mark[i - 1]; long long min1 = 1000000000005; for (i = 1; i <= k; i++) { long long x = i; long long pos = 0; long long s = 0; bool f = 0; while (pos < n) { if (mark[pos] != pos && mark[pos] == pos - x) { f = 1; break; } else if (mark[pos] != pos) pos = mark[pos]; pos += x; s += a[i]; } if (f == 0) { min1 = min(min1, s); } } if (min1 == 1000000000005) min1 = -1; cout << min1 << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, m, k, s; int nxt[N], path[N]; bool bl[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= m; i++) { cin >> s; bl[s] = true; } for (int i = 0; i <= n; i++) { if (bl[i]) { if (i == 0) { nxt[i] = -1; } else { nxt[i] = nxt[i - 1]; } } else { nxt[i] = i; } } if (bl[0]) { return puts("-1"), 0; } long long ans = LLONG_MAX; for (int i = 1; i <= k; i++) { cin >> s; long long ct = 0; int pos = 0; while (pos < n) { if (pos == -1 || path[pos] == i) { break; } path[pos] = i; ct++; if (pos + i >= n) { pos = n; break; } pos = nxt[pos + i]; } if (pos >= n) { ans = min(ans, ct * s); } } cout << (ans == LLONG_MAX ? -1 : ans) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; const int N = (int)(2e6 + 5); int n, m, k, s; bool block[N]; int pr[N]; int check(int len) { int res = 0; int p = 0; while (p < n) { ++res; p += len; if (block[p]) p = pr[p]; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(); cin >> n >> m >> k; for (int i = 0; i < m; i++) cin >> s, block[s] = true; if (block[0]) { cout << -1 << endl; return 0; } int mx = 0; int c = 0; for (int i = 0; i < n; i++) { if (block[i]) pr[i] = pr[i - 1], ++c; else pr[i] = i, c = 0; mx = max(mx, c); } long long res = 1LL * N * N; int a; for (int i = 1; i <= mx; i++) cin >> a; for (int i = mx + 1; i <= k; i++) cin >> a, res = min(res, 1LL * check(i) * a); if (res == 1LL * N * N) res = -1; cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void in(T &x) { T c = getchar(); while (((c < 48) || (c > 57)) && (c != '-')) c = getchar(); bool neg = false; if (c == '-') neg = true; x = 0; for (; c < 48 || c > 57; c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) x = (x * 10) + (c - 48); if (neg) x = -x; } const int MAXN = 1e6 + 10; const long long INF = 1e15; bool blocked[MAXN]; int cost[MAXN]; int R[MAXN]; int n, m, k; int main() { in(n), in(m), in(k); for (int i = 0; i < m; i++) { int p; in(p); blocked[p] = true; } if (blocked[0]) { puts("-1"); return 0; } for (int i = 1; i <= k; i++) { in(cost[i]); } int rt = -1; for (int i = n; i >= 0; i--) { if (blocked[i] == false) { rt = i; } R[i] = rt; } long long ans = INF; for (int j = 1; j <= k; j++) { bool ok = true; long long cnt = 0; for (int pos = n; pos > 0;) { int nxt = max(0, pos - j); if (R[nxt] == -1 || R[nxt] >= pos) { ok = false; break; } pos = R[nxt]; cnt++; } if (ok) ans = min(ans, cnt * cost[j]); } printf("%lld\n", ans == INF ? -1ll : ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, a; long long ans = 1e18; scanf("%d%d%d", &n, &m, &k); vector<int> lst(n + 1, 0); vector<int> sz(k + 1); for (int i = 0; i < m; i++) { scanf("%d", &a); lst[a] = -1; } if (lst[0] == -1) { cout << -1; return 0; } for (int i = 1; i <= k; i++) { scanf("%d", &sz[i]); } for (int i = 0; i <= n; i++) { if (lst[i] != -1) lst[i] = i; else lst[i] = lst[i - 1]; } for (int i = 1; i <= k; i++) { int j = 0; long long s = 0; bool f = true; while (j < n) { if (j + i >= n || lst[j + i] != j) { s++; if (j + i <= n) j = lst[j + i]; else j = n; } else { s = 1e18; f = false; break; } } if (f) s = s * sz[i]; ans = min(ans, s); } if (ans == 1e18) cout << -1; else cout << ans; return 0; }
#include <bits/stdc++.h> template <typename T> T max(T x, T y) { return (x > y) ? x : y; } template <typename T> T min(T x, T y) { return (x < y) ? x : y; } template <typename T> bool chkmax(T &x, T y) { return (x >= y) ? 0 : (x = y, 1); } template <typename T> bool chkmin(T &x, T y) { return (x <= y) ? 0 : (x = y, 1); } template <typename T> T read(T &in) { in = 0; char ch; T f = 1; while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) in = in * 10 + ch - '0', ch = getchar(); return in *= f; } static const int MAX1 = 1000000 + 11; int n, m, k; int s[MAX1], a[MAX1], pre[MAX1]; bool b[MAX1]; long long Get(int x) { int i = 0, c = 0; while (i < n) { if (b[i]) i = pre[i]; ++c, i += x; } return 1ll * c * a[x]; } int main() { read(n), read(m), read(k); for (int i = (1), ir = (m); i <= (ir); ++i) read(s[i]), b[s[i]] = 1; for (int i = (1), ir = (k); i <= (ir); ++i) read(a[i]); if (m && s[1] == 0) return puts("-1"), 0; int MAX_LEN = 0, T_LEN = 0; for (int i = (1), ir = (n); i <= (ir); ++i) { if (b[i]) chkmax(MAX_LEN, ++T_LEN), pre[i] = pre[i - 1]; else T_LEN = 0, pre[i] = i; } if (++MAX_LEN > k) return puts("-1"), 0; long long Ans = LONG_LONG_MAX; for (int i = (MAX_LEN), ir = (k); i <= (ir); ++i) chkmin(Ans, Get(i)); printf("%lld\n", Ans); return 0; }
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" using namespace std; const long long bm = 3 * (long long)(1e6); long long n, m, k; bool blocked[bm]; long long ui[bm]; long long ga[bm]; long long tc(long long x) { long long cc = 0; long long p = 0; while (p < n) { if (p == ga[p + x]) return 1000000000000000000; else { p = ga[p + x]; ++cc; } } return cc * ui[x]; } long long solve() { scanf("%lld %lld %lld", &n, &m, &k); for (long long i = 0; i < m; i++) { long long x; scanf("%lld", &x); blocked[x] = true; } if (blocked[0]) return -1; for (long long i = 0; i < k; i++) scanf("%lld", &ui[i + 1]); long long lf = 0; for (long long i = 0; i < bm; i++) { if (i <= n && blocked[i] == false) { lf = i; } ga[i] = lf; } long long rd = 1000000000000000000; for (long long i = 0; i < k; i++) rd = min(rd, tc(i + 1)); if (rd == 1000000000000000000) rd = -1; return rd; } signed main() { printf("%lld\n", solve()); }
#include <bits/stdc++.h> using namespace std; const int maxN = 1000013; int n, k, m; long long a[maxN], s[maxN], pr[maxN], cnt[maxN]; int main() { cin >> n >> m >> k; for (int i = 0; i <= n; ++i) pr[i] = i; for (int i = 0; i < m; ++i) { cin >> s[i]; if (s[i]) pr[s[i]] = pr[s[i] - 1]; else { cout << -1; return 0; } } for (int i = 1; i <= k; ++i) cin >> a[i]; int mn = 1; for (int i = 1; i <= n; ++i) mn = (((mn) < (i - pr[i - 1])) ? (i - pr[i - 1]) : (mn)); if (mn > k) { cout << -1; return 0; } for (int i = mn; i <= k; ++i) { int pos = 0, c = 0; while (pos < n) { pos += i; ++c; if (pos >= n) break; pos = pr[pos]; } cnt[i] = c; } long long ans = cnt[mn] * a[mn]; for (int i = mn; i <= k; ++i) { ans = (((ans) > (cnt[i] * a[i])) ? (cnt[i] * a[i]) : (ans)); } cout << ans; getchar(); getchar(); return 0; }
#include <bits/stdc++.h> using namespace std; int a[2000005], n, pre[2000005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long m, k, ans = 1e15; cin >> n >> m >> k; for (int i = 0; i < 2000005; ++i) a[i] = 1; for (int i = 0, x; i < m; ++i) { cin >> x; a[x] = 0; } for (int i = 0, last = -1; i < 2000005; ++i) { if (a[i]) last = i; pre[i] = last; } if (!a[0]) return cout << -1, 0; for (int i = 1; i <= k; cin >> a[i++]) ; for (int i = 1; i <= k; ++i) { int cur = 0; long long cost = 0; while (cur < n) { cost += a[i]; if (pre[cur + i] == cur) { cost = 1e17; break; } cur = pre[cur + i]; } ans = min(ans, cost); } cout << (ans > 1e13 ? -1 : ans); }
#include <bits/stdc++.h> using namespace std; const long long oo = 1e14; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> prev(n), s(m), a(k); for (int i = (0); i < (n); ++i) prev[i] = i; for (int i = (0); i < (m); ++i) { int x; cin >> x; prev[x] = -1; } for (int i = (0); i < (k); ++i) cin >> a[i]; if (prev[0] == -1) { cout << -1 << '\n'; return 0; } for (int i = (1); i < (n); ++i) if (prev[i] == -1) prev[i] = prev[i - 1]; long long ans = oo; for (int i = (1); i < (k + 1); ++i) { int j = 0, cnt = 0; while (j + i < n) { if (prev[j + i] == j) { cnt = -1; break; } j = prev[j + i]; cnt++; } if (cnt != -1) ans = min(ans, 1LL * (cnt + 1) * a[i - 1]); } cout << (ans < oo ? ans : -1) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 4e18; const long long ninf = -inf; const int imax = 2e9; const int MAX = 1e6 + 100; int n, m, k; int h[MAX], last[MAX]; long long s[MAX]; long long a[MAX]; long long solve(int val) { long long ans = 0; int repeat = 0; for (int i = 0; i < n;) { if (!h[i]) { ans++; i += val; } else { i = last[i]; } if (i == repeat) { return 1e17; } else { repeat = i; } } return ans; } int main() { ios_base::sync_with_stdio(false); cin >> n >> m >> k; for (int i = 1; i <= m; i++) { cin >> s[i]; h[s[i]] = 1; } for (int i = 1; i <= k; i++) { cin >> a[i]; } int last_yes = 0; for (int i = 0; i <= n; i++) { if (!h[i]) { last_yes = i; } last[i] = last_yes; } long long cont = 0, mcont = 0; for (int i = 0; i <= n; i++) { if (h[i]) { cont++; mcont = max(mcont, cont); } else { mcont = max(mcont, cont); cont = 0; } } long long maxAns = 1e16; for (int i = mcont + 1; i <= k; i++) { long long ct = solve(i); ; if (ct < 1e16) maxAns = min(ct * a[i], maxAns); } if (maxAns >= 9e15) { cout << -1 << endl; } else { cout << maxAns << endl; } }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long min(long long a, long long b) { return (a < b) ? a : b; } long long max(long long a, long long b) { return (a > b) ? a : b; } long long fp(long long a, long long b) { if (b == 0) return 1; long long x = fp(a, b / 2); x = (x * x) % mod; if (b & 1) x = (x * a) % mod; return x; } const long long N = 1e6 + 5; long long a[N], blk[N] = {0}, prv[N]; long long n; long long solve(long long k, long long c) { long long cur = 0, tot = 0; while (1) { long long x = cur + k; tot += c; if (x >= n) return tot; x = prv[x]; if (x <= cur) { return 1e18; } cur = x; } return 1e18; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long m, k, x; cin >> n >> m >> k; for (long long i = 1; i <= m; i++) { cin >> x; blk[x] = 1; } prv[0] = 0; for (long long i = 1; i < N; i++) { if (blk[i]) prv[i] = prv[i - 1]; else prv[i] = i; } if (blk[0]) { cout << -1; return 0; } long long ans = 1e18; for (long long i = 1; i <= k; i++) { cin >> x; ans = min(ans, solve(i, x)); } if (ans == 1e18) ans = -1; cout << ans; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000008; const long long oo = 1LL << 50; bool blocked[MAXN]; long long prices[MAXN]; int lastfree[2 * MAXN]; vector<pair<long long, long long> > estimates; int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < n; i++) { blocked[i] = false; } int x; for (int i = 0; i < m; i++) { scanf("%d", &x); blocked[x] = true; } int mxbl = 0, cbl = 0; int lstf = 0; for (int i = 0; i < n; i++) { if (blocked[i]) { cbl++; mxbl = max(mxbl, cbl); } else { cbl = 0; lstf = i; } lastfree[i] = lstf; } for (int i = n; i < 2 * n; i++) { lastfree[i] = i; } for (int i = 1; i <= k; i++) { scanf("%lld", &prices[i]); } if (blocked[0] || mxbl >= k) { printf("-1\n"); return 0; } long long minpr = oo; for (int i = k; i > mxbl; i--) { if (prices[i] > minpr) continue; minpr = prices[i]; long long epr = (n + i - 1) / i * prices[i]; estimates.push_back(make_pair(epr, i)); } sort(estimates.begin(), estimates.end()); long long minres = oo; for (unsigned i = 0; i < estimates.size(); i++) { if (estimates[i].first >= minres) break; int clamp = estimates[i].second; int cpos = 0; long long cpr = 0; while (cpos < n) { cpr += prices[clamp]; cpos = lastfree[cpos + clamp]; } minres = min(minres, cpr); } printf("%lld\n", minres); return 0; }
#include <bits/stdc++.h> using namespace std; const int SIZE = 1 << 10; int pointer = SIZE; char buffer[SIZE]; char Advance() { if (pointer == SIZE) { fread(buffer, 1, SIZE, stdin); pointer = 0; } return buffer[pointer++]; } int Read() { int answer = 0; char ch = Advance(); while (!isdigit(ch)) ch = Advance(); while (isdigit(ch)) { answer = answer * 10 + ch - '0'; ch = Advance(); } return answer; } const int MAXN = 1000000; const long long INF = 1000000000000000000LL; bool out[1 + MAXN]; int toLeft[1 + MAXN]; int Cover(int n, int l) { int answer = 0, where = 0; while (1) { answer++; where += l; if (where >= n) break; where = toLeft[where]; } return answer; } int main() { int n = Read(), m = Read(), k = Read(); for (int i = 1; i <= m; i++) { int x = Read(); out[x] = true; } if (out[0]) { printf("-1\n"); return 0; } int start = 1; for (int i = 0; i <= n - 1; i++) { if (!out[i]) toLeft[i] = i; else toLeft[i] = toLeft[i - 1]; start = max(start, i - toLeft[i] + 1); } if (start > k) { printf("-1\n"); return 0; } long long answer = INF; for (int i = 1; i <= k; i++) { int cost = Read(); if (i < start) continue; answer = min(answer, 1LL * cost * Cover(n, i)); } printf("%I64d\n", answer); return 0; }
#include <bits/stdc++.h> using namespace std; int q[1000005]; int w[1000005]; int vis[1000005]; int d[1100005]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= m; i++) scanf("%d", &q[i]), vis[q[i]] = 1; for (int i = 1; i <= k; i++) scanf("%d", &w[i]); if (vis[0] && m > 0) { puts("-1"); return 0; } for (int i = 1; i <= n; i++) { if (vis[i]) d[i] = d[i - 1]; else d[i] = i; } for (int i = 1; i <= k; i++) d[n + i] = n + i; long long ans = 1e14; for (int i = 1; i <= k; i++) { long long sum = 0; bool f = true; int loc = 0; while (1) { if (loc >= n) break; if (loc == d[loc + i]) { f = false; break; } loc = d[loc + i]; sum += w[i]; } if (f) ans = min(ans, sum); } if (ans != 1e14) printf("%lld\n", ans); else puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> pos; int a[1000005]; void up(long long &a, long long b) { if (a == -1 || b < a) a = b; } int solve(int x, int n) { int stp = 0, re = 0; while (1) { if (stp + x >= n) { re++; break; } auto it = upper_bound(pos.begin(), pos.end(), stp + x); if (it == pos.begin()) return -1; it--; if (*it <= stp) return -1; re++; stp = *it; } return re; } int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); int stp = 0; for (int i = 0; i < m; i++) { int x; scanf("%d", &x); while (stp < x) pos.push_back(stp++); stp++; } while (stp < n) pos.push_back(stp++); for (int i = 1; i <= k; i++) { scanf("%d", &a[i]); } if (pos.empty() || pos[0] != 0) { printf("-1\n"); return 0; } long long ans = -1; for (int i = 1; i <= k; i++) { int x = solve(i, n); if (x != -1) up(ans, 1ll * x * a[i]); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(nullptr)->sync_with_stdio(false); long long n, m, k; cin >> n >> m >> k; vector<bool> bad(n); for (long long i = 0; i < m; i++) { long long x; cin >> x; bad[x] = true; } vector<long long> pv(n); queue<long long> q; long long lst = -1; for (long long i = 0; i < n; i++) { if (!bad[i]) lst = i; pv[i] = lst; } long long ans = LLONG_MAX; for (long long jp = 1; jp <= k; jp++) { long long cost = 0; long long c; cin >> c; long long cur = 0; if (bad[cur]) goto done; while (true) { cost += c; if (cur + jp >= n) break; long long nxt = pv[cur + jp]; if (nxt == cur) goto done; cur = nxt; } ans = min(ans, cost); done:; } if (ans == LLONG_MAX) ans = -1; cout << ans << "\n"; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 }; template <typename T> ostream &operator<<(ostream &cout, vector<T> &a) { for (size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout; } template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a) { for (size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout; } bool bad[1000000]; int a[1000000]; int l[1000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k, m; cin >> n >> m >> k; for (int i = 0; i < m; ++i) { int x; cin >> x; bad[x] = true; } if (bad[0]) { cout << -1 << '\n'; return 0; } int cur = 0; int mx = 0; for (int i = 1; i < n; ++i) { if (bad[i]) { l[i] = cur; } else { l[i] = cur = i; } mx = max(mx, i - cur); } if (mx >= k) { cout << -1 << '\n'; return 0; } for (int i = 0; i < k; ++i) { cin >> a[i]; } long long ans = LLONG_MAX; for (int i = mx; i < k; ++i) { int st = 0; int cc = 0; while (true) { ++cc; if (st + i + 1 >= n) break; st = l[st + i + 1]; } ans = min((long long)cc * a[i], ans); } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int s[maxn], a[maxn], prv[maxn]; int n, m, k; bool check(int l, int &ans) { int x = 0; ans = 0; while (x < n) { ++ans; int to = x + l - 1; if (to >= n - 1) break; if (s[to + 1]) { if (prv[to + 1] == x) return false; x = prv[to + 1]; continue; } x = to + 1; } return true; } int main() { scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < m; ++i) { int x; scanf("%d", &x); s[x] = 1; } if (s[0]) { puts("-1"); return 0; } s[n] = 1; for (int i = 1; i <= k; ++i) scanf("%d", &a[i]); vector<int> cand = {k}; int p = a[k]; for (int i = k - 1; i >= 1; --i) { if (p > a[i]) cand.push_back(i); p = min(p, a[i]); } for (int i = 0; i <= n; ++i) { if (s[i]) prv[i] = prv[i - 1]; else prv[i] = i; } long long ans = 1e15; int x; for (int i : cand) { if (check(i, x)) ans = min(ans, x * 1ll * a[i]); } if (ans == 1e15) ans = -1; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, k, a[1000010], h[1000010], pre[1000010]; int main() { cin >> n >> m >> k; for (int i = 1; i <= m; i++) { int tmp; scanf("%d", &tmp); h[tmp] = 1; } if (h[0]) return cout << -1 << endl, 0; int now = 0, len = 0; for (int i = 0; i <= n; i++) { if (h[i]) now++, pre[i] = pre[i - 1]; else now = 0, pre[i] = i; len = max(len, now); } for (int i = 1; i <= k; i++) scanf("%d", &a[i]); if (len >= k) return cout << -1 << endl, 0; long long ans = 1LL << 60; for (int i = len + 1; i <= k; i++) { long long ret = 0, now = 0; while (now < n) { now = pre[now]; ret += a[i]; now = now + i; } ans = min(ans, ret); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int sz = 1e6 + 5; int n, m, k; bitset<sz> block; long long p[sz], amt[sz], lst[sz]; void input() { scanf("%d %d %d", &n, &m, &k); int tmp; for (int i = 0; i < m; i++) { scanf("%d", &tmp); block[tmp] = 1; } for (int i = 0; i < k; i++) scanf("%d", &p[i + 1]); int cur = -1; for (int i = 0; i < n; i++) { if (!block[i]) cur = i; lst[i] = cur; } } int main() { input(); if (block[0]) { cout << -1 << '\n'; return 0; } long long bst = 1e15; for (int l = 1; l <= k; l++) { int ind = 0, mxColored = -1; while (mxColored < n - 1 && ind < n) { mxColored = min(ind + l - 1, n - 1); amt[l]++; if (mxColored == n - 1) break; int nxt = lst[mxColored + 1]; if (nxt == ind) break; else ind = nxt; } if (mxColored < n - 1) amt[l] = 2e12; bst = min(bst, p[l] * amt[l]); } if (bst <= 1e12) printf("%lld\n", bst); else printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 3; const long long OO = 1e18; int main(int argc, char* argv[]) { ios::sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; vector<int> s(n + 1, 0); for (int(i) = (0); (i) < (m); (i)++) { int tmp; cin >> tmp; s[tmp] = 1; } if (s[0]) { cout << -1 << endl; return 0; } int now = 0; vector<int> prev(n + 1, 0); for (int(i) = (0); (i) < (n + 1); (i)++) { if (!s[i]) { now = i; prev[i] = now; } else { prev[i] = now; } } vector<int> a; a.resize(k, 0); for (int(i) = (0); (i) < (k); (i)++) { cin >> a[i]; } long long bestAns = OO; for (int(K) = (0); (K) < (k); (K)++) { int pos = 0; long long ans = 0; bool can = true; for (;;) { if (pos == n) { break; } int nxt = pos + (K + 1); nxt = min(nxt, n); nxt = prev[nxt]; if (nxt == pos) { can = false; break; } ans += a[K]; pos = nxt; } if (!can) continue; bestAns = min(bestAns, ans); } if (bestAns == OO) { cout << -1 << endl; } else { cout << bestAns << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long pos[1000005] = {0}; long long cost[1000005] = {0}; long long dp[1000005] = {0}; long long foo[1000005] = {0}; int main() { ios_base::sync_with_stdio(false); long long n, m, k, i, temp; cin >> n >> m >> k; for (i = 0; i < m; i++) { cin >> temp; temp++; pos[temp] = 1; } for (i = 1; i <= k; i++) { cin >> cost[i]; } if (pos[1] == 1) { cout << "-1" << endl; return 0; } dp[1] = 1; long long bheem = 1; for (i = 2; i <= n; i++) { if (pos[i] == 0) { dp[i] = i; } else { dp[i] = dp[i - 1]; } bheem = max(bheem, i - dp[i]); } long long c = cost[k]; for (i = k - 1; i >= 1; i--) { if (cost[i] < c) { c = cost[i]; } else { foo[i] = 1; } } long long ans = 1000000000000000, flag = 0, flag1 = 0; for (i = bheem; i <= k; i++) { if (foo[i] == 1) continue; long long me = 0; flag = 0; long long t = 1, last = 0; while (1) { me += cost[i]; if (t <= last) { flag = 0; break; } last = t; t += i; if (t > n) { flag1 = 1; flag = 1; break; } t = dp[t]; } if (flag == 1) ans = min(me, ans); } if (flag1 == 0) { cout << "-1" << endl; } else { cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; int block[m], cost[k + 1]; int region[n]; int nearest[n]; for (int i = 0; i < n; i++) { region[i] = 0; nearest[i] = 0; } for (int i = 0; i < m; i++) { cin >> block[i]; region[block[i]] = 1; } int prev = -1; for (int i = 0; i < n; i++) { if (region[i] == 0) { nearest[i] = i; prev = i; } else nearest[i] = prev; } map<int, int> HashMap; for (int i = 1; i <= k; i++) { cin >> cost[i]; HashMap[cost[i]] = i; } long long int ans = LLONG_MAX; for (pair<int, int> p : HashMap) { int price = p.first; int step = p.second; int start = 0; long long int total = 0; int flag = 0; while (start < n) { if (region[start] == 0) { total += price; start += step; continue; } if (nearest[start] <= start - step or nearest[start] < 0) { flag = 1; break; } else { total += price; start = nearest[start] + step; } } if (flag == 0) { ans = min(ans, total); } } if (ans == LLONG_MAX) cout << -1 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; int s[maxn], a[maxn], vis[maxn], b[maxn]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; i++) scanf("%d", &s[i]), vis[s[i]] = 1; for (int i = 1; i <= k; i++) scanf("%d", &a[i]); if (vis[0]) b[0] = -1; for (int i = 1; i < n; i++) { if (vis[i]) b[i] = b[i - 1]; else b[i] = i; } int f = 0, cnt = 0; long long res = INF; for (int i = 1; i <= k; i++) { f = cnt = 0; for (int j = 0; j < n;) { if (vis[j] == 0) j += i, cnt++; else { if (b[j] == -1 || j - b[j] >= i) { f = 1; break; } else j = i + b[j], cnt++; } } if (f) continue; res = min(res, 1ll * cnt * a[i]); } if (res == INF) res = -1; printf("%lld\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; inline long long getnum() { char c = getchar(); long long num, sign = 1; for (; c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (num = 0; c >= '0' && c <= '9';) { c -= '0'; num = num * 10 + c; c = getchar(); } return num * sign; } int X[1000005], A[1000005]; int nxt(int x) { if (X[x] == x) return x; return X[x] = nxt(X[x]); } int main() { int n = getnum(), m = getnum(), k = getnum(); for (int i = 0; i < n; i++) X[i] = i; X[n] = n; for (int i = 1; i <= m; i++) { int x = getnum(); X[x] = x + 1; } for (int i = 1; i <= k; i++) A[i] = getnum(); long long ans = LLONG_MAX; for (int i = 1; i <= k; i++) { long long tot = 0; for (int j = n - 1; j >= 0;) { int y = j - i + 1; if (y < 0) y = 0; int x = nxt(y); if (x > j) { tot = LLONG_MAX; break; } tot += A[i]; j = x - 1; } ans = min(ans, tot); } if (ans == LLONG_MAX) ans = -1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long n, m, k, ans = (1ll << 50); long long b[1000005], c[1000005], p[1000005]; int main() { scanf("%lld%lld%lld", &n, &m, &k); long long x; for (long long i = 1; i <= m; i++) { scanf("%lld", &x); b[x] = 1; } for (long long i = 1; i <= k; i++) { scanf("%lld", &c[i]); } if (b[0]) { puts("-1"); return 0; } for (long long i = 1; i <= n; i++) { if (b[i]) p[i] = p[i - 1]; else p[i] = i; } bool f; long long ct; for (long long i = 1; i <= k; i++) { x = 0; f = 1; ct = 0; while (x < n) { x = p[x]; if (x + i >= n) { ct++; break; } if (p[x + i] <= x) { f = 0; break; } x += i; ct++; } if (f) { ans = min(ans, ct * c[i]); } } if (ans == (1ll << 50)) { puts("-1"); } else { cout << ans; } }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; long long n, a[2000001], pre[2000001], k, d, m, c[2000001], w, x[2000001], res; bool f[2000001]; int main() { cin >> n >> m >> k; for (int i = 0; i < m; i++) { int r; scanf("%d", &r); f[r] = true; } for (int i = 1; i <= k; i++) scanf("%d", &c[i]); if (f[0]) { printf("-1\n"); return 0; } for (int i = 1; i <= n; i++) pre[i] = (f[i - 1]) ? pre[i - 1] : i - 1; for (int i = 1; i <= n + n; i++) x[i] = (f[i]) ? x[i - 1] : i; w = 0; for (int i = 1; i <= n; i++) { w = max(w, i - pre[i]); } if (w > k) { printf("-1\n"); return 0; } long long ans = 1e18; for (int i = w; i <= k; i++) { res = 0; d = 0; while (d < n) d = x[d + i], res += c[i]; ans = min(ans, res); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int N = 1e6 + 7; long long cost[N]; int vis[N], n, m, k; int pre[N]; int main(void) { scanf("%d", &n), scanf("%d", &m), scanf("%d", &k); int i; for (i = 1; i <= m; ++i) { int x; scanf("%d", &x); vis[x] = 1; } for (i = 1; i <= k; ++i) scanf("%lld", &cost[i]); long long ans = 1ll << 50; if (vis[0]) return puts("-1"), 0; for (i = 0; i < n; ++i) { if (vis[i]) pre[i] = pre[i - 1]; else pre[i] = i; } for (i = 1; i <= k; ++i) { int cur = 0; long long tans = 0; while (cur < n) { if (vis[cur]) { int p = pre[cur]; int tcur = p + i; if (tcur <= cur) { tans = 1ll << 50; break; } else { cur = tcur; tans += cost[i]; } } else { tans += cost[i]; cur += i; } } ans = min(tans, ans); } printf("%lld\n", ans == 1ll << 50 ? -1ll : ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long double epsylon = 1e-9; const std::string PROGRAM_NAME = "ivo"; int main() { int n, m, k; cin >> n >> m >> k; vector<char> a(n + 1, 0); for (int i = 0; i < m; ++i) { int x; scanf("%d", &x); a[x] = 1; } a[n] = 1; int worst = 0; int cur = 0; for (int i = 0; i < n; ++i) { if (a[i]) { cur++; worst = max(worst, cur); } else { cur = 0; } } if (worst > k || a[0]) { cout << -1 << endl; return 0; } vector<long long> costs(k); for (int i = 0; i < (int)costs.size(); ++i) { int temp; scanf("%d", &temp); costs[i] = temp; } vector<int> prev(n + 1); prev[0] = 0; int last_good = 0; for (int i = 1; i <= n; ++i) { if (a[i] == 0) { last_good = i; prev[i] = i; } else { prev[i] = last_good; } } long long best = -1; for (int step = worst + 1; step <= k; ++step) { long long total = 0; long long cur = 0; while (cur < n) { total += costs[step - 1]; cur += step; if (cur < n && a[cur]) { cur = prev[cur]; } } if (best == -1 || total < best) { best = total; } } cout << best << endl; return 0; }
#include <bits/stdc++.h> const int M = 1e9 + 7; void MultL(long long int &a, long long int b) { a = (a * b) % M; } void AddL(long long int &a, long long int b) { a = (a + (b + M)) % M; } long long int Mult(long long int a, long long int b) { return (a * b) % M; } long long int Add(long long int a, long long int b) { return (a + (b + M)) % M; } using namespace std; int SIZE = 50; vector<int> gaps; vector<int> cost; int n, m, k; vector<bool> field; vector<int> pre; int good(int p) { int cover = 0; int res = 0; while (cover < field.size()) { if (!field[cover]) { if (pre[cover] == -1) { return -1; } int new_cover = pre[cover] + p + 1; if (new_cover <= cover) { return -1; } cover = new_cover; ++res; continue; } cover += p + 1; ++res; } return res; } int main() { std::ios::sync_with_stdio(false); cin >> n >> m >> k; gaps = vector<int>(m); cost = vector<int>(k); for (int i = 0; i < m; ++i) cin >> gaps[i]; for (int i = 0; i < k; ++i) cin >> cost[i]; field = vector<bool>(n, true); pre = vector<int>(n, -1); for (int i = 0; i < m; ++i) { field[gaps[i]] = false; } int last_av = -1; for (int i = 0; i < field.size(); ++i) { if (field[i]) { last_av = i; } else { pre[i] = last_av; } } long long int res = -1; for (int i = 0; i < k; ++i) { long long int curr = good(i); if (curr == -1) { continue; } if (res == -1) { res = cost[i] * curr; continue; } res = min(res, cost[i] * curr); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[1000010]; int blo[1000010]; int ri[1000010]; long long ans; const long long INF = 1e18; long long cal(long long x) { long long r = 0; long long res = 0; while (r < n) { if (ri[r] == -1) return INF; long long tmp = ri[r] + x; res++; if (tmp <= r) return INF; r = tmp; } return res; } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i <= n; i++) blo[i] = 1; for (int i = 1; i <= m; i++) { int tmp; scanf("%d", &tmp); blo[tmp] = 0; } for (int i = 1; i <= k; i++) scanf("%d", &a[i]); for (int i = 0; i <= n; i++) { if (blo[i] == 1) ri[i] = i; else { if (i == 0) ri[i] = -1; else ri[i] = ri[i - 1]; } } ans = INF; for (int l = 1; l <= k; l++) { long long tmp = cal(l); if (tmp == INF) continue; ans = min(ans, tmp * a[l]); } if (ans == INF) { printf("-1\n"); return 0; } printf("%lld\n", ans); }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast,no-stack-protector") using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...); } function<void(void)> ____ = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }; template <typename T> vector<T> &operator<<(vector<T> &__container, T x) { __container.push_back(x); return __container; } template <typename T> ostream &operator<<(ostream &out, vector<T> &__container) { for (T _ : __container) out << _ << ' '; return out; } void sci() {} template <typename... Args> void sci(int &x, Args &...args) { scanf("%d", &x); sci(args...); } void scl() {} template <typename... Args> void scl(long long int &x, Args &...args) { scanf("%lld", &x); scl(args...); } const int MAXN = 1e6 + 7; void solve() { int n, m, k; sci(n, m, k); vector<bool> pos(n, false); for (int i = 1; i <= m; i++) { int x; sci(x); pos[x] = true; } vector<int> pre(n, 0); for (int i = 1; i < n; i++) pre[i] = pos[i] ? pre[i - 1] : i; vector<int> A(k); for (int &x : A) sci(x); if (pos[0]) { cout << -1 << "\n"; return; } long long int ret = LLONG_MAX; for (int x = 0; x < k; x++) { int last = 0, __cnt = 0; while (last < n) { __cnt++; if (last - pre[last] - 1 >= x) { __cnt = -1; break; } last = pre[last] + x + 1; } if (__cnt != -1) ((ret) = (ret) < (1ll * __cnt * A[x]) ? (ret) : (1ll * __cnt * A[x])); } cout << (ret == LLONG_MAX ? -1 : ret) << "\n"; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, m, k, s[maxn], a[maxn], pre[maxn]; bool flag[maxn]; int main(int argc, char const *argv[]) { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < m; i++) scanf("%d", s + i), flag[s[i]] = true; for (int i = 0; i < k; i++) scanf("%d", a + i); pre[0] = 0; for (int i = 1; i <= n; i++) if (!flag[i - 1]) pre[i] = i - 1; else pre[i] = pre[i - 1]; long long ans = LLONG_MAX; for (int i = 0; i < k; i++) { bool ff = false; int j = 0, tmp = 0, lst; while (j < n) { while (flag[j] && pre[j] > lst) j = pre[j]; if (flag[j]) { ff = true; break; } tmp++; lst = j; j += i + 1; } if (ff) continue; ans = min(ans, 1ll * tmp * a[i]); } if (ans == LLONG_MAX) printf("-1\n"); else printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const long long MOD = (int)1e9 + 7; const long long MOR = (int)1e9 + 31; const long long INF = (long long)1e15 + 100; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const int MAXN = (int)1e6 + 5; const double pi = 3.14159265358979323846; const int SZ = 1; int n, m, k, pr[MAXN], c[MAXN], pos[MAXN]; bool us[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 0; i < m; i++) { int x; cin >> x; us[x] = 1; } for (int i = 1; i <= k; i++) cin >> c[i]; if (us[0]) { cout << -1; return 0; } int p = 0, len = 0; for (int i = 0; i <= n; i++) { len = max(i - p, len); if (!us[i]) p = i; else pr[i] = p; } if (len > k) { cout << -1; return 0; } long long ans = INF; for (int i = len; i <= k; i++) { long long cnt = 0; for (int j = 0; j <= n;) { cnt++; if (j + i >= n) break; if (us[j + i]) j = pr[j + i]; else j = j + i; } ans = min(ans, cnt * (long long)c[i]); } cout << ans; }
#include <bits/stdc++.h> using namespace std; long long int b[1000005], last[1000005], c[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int i, n, m, k, ans, f, j, x, cnt; cin >> n >> m >> k; for (i = 0; i < m; i++) { cin >> x; b[x] = 1; } for (i = 1; i <= k; i++) cin >> c[i]; if (b[0] == 1) { cout << -1 << endl; return 0; } for (i = 0; i <= n; i++) { if (b[i]) last[i] = last[i - 1]; else last[i] = i; } ans = 1e18; for (i = 1; i <= k; i++) { cnt = 0; f = 1; for (j = 0; j < n;) { cnt++; if (j + i >= n) break; if (last[j + i] == j) { f = 0; break; } else j = last[j + i]; } if (f) { ans = min(ans, cnt * c[i]); } } if (ans != 1e18) cout << ans << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; int cvt[1000010]; int cost[1000010]; int n, m, k; int main(void) { scanf("%d%d%d", &n, &m, &k); int tmp; while (m--) { scanf("%d", &tmp); if (tmp == 0) { printf("-1"); return 0; } cvt[tmp] = 1; } for (int i = 1; i <= k; i++) scanf("%d", &cost[i]); int lastok = 0; int maxlen = 0; int tlen = 0; for (int i = 1; i <= n; i++) { if (cvt[i]) { cvt[i] = lastok; tlen++; maxlen = max(maxlen, tlen); } else { lastok = i; cvt[i] = i; tlen = 0; } } if (maxlen + 1 > k) { printf("-1"); return 0; } long long ans = 1ll * 2147483647 * 2147483647; for (int t = max(1, maxlen + 1); t <= k; t++) { int tcos = 0; int pos = 0; while (pos < n) { tcos++; pos = pos + t >= n ? n : cvt[pos + t]; } ans = min(ans, 1ll * tcos * cost[t]); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; bool can[MAXN]; int val[MAXN], lx = 0, tmp = 0, pre = 0, precan[MAXN], n, m, k; int main() { memset(can, 1, sizeof(can)); scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; i++) { int tmp; scanf("%d", &tmp); can[tmp] = 0; } if (!can[0]) { puts("-1"); return 0; } for (int i = 1; i <= k; i++) { scanf("%d", &val[i]); } for (int i = 0; i < n; i++) { if (can[i]) tmp = 0, pre = i; else tmp++, lx = max(lx, tmp), precan[i] = pre; } long long tmpans = 0, ans = (1ll << 55); for (int l = lx + 1; l <= k; l++) { tmpans = 0; for (int j = 0; j < n; j += (l)) { if (!can[j]) j = precan[j]; tmpans += val[l]; } if (tmpans != 0) ans = min(ans, tmpans); } if (ans != (1ll << 55)) cout << ans << endl; else puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238462643383279502884197169399375105820974944; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long ans = 1000000000; ans *= 10000000; long long tempans = ans; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, k; cin >> n >> m >> k; int s[m + 1]; for (int i = 0; i < m; i++) cin >> s[i]; s[m] = n + 5; int a[k + 1]; for (int i = 1; i <= k; i++) cin >> a[i]; int haha[n], curr = 0; for (int i = 0; i < n; i++) { if (s[curr] == i) { haha[i] = 0; curr++; } else haha[i] = 1; } if (haha[0] == 0) { cout << -1 << endl; return 0; } int prev[n]; prev[0] = 0; for (int i = 1; i < n; i++) { if (haha[i] == 1) prev[i] = i; else prev[i] = prev[i - 1]; } for (int i = 1; i <= k; i++) { long long cnt = 0, check = 1; int pos = 0, temppos; while (pos < n) { temppos = prev[pos]; temppos += i; if (temppos <= pos) { check = 0; break; } pos = temppos; cnt++; } if (check) ans = min(ans, cnt * a[i]); } if (ans != tempans) cout << ans; else cout << -1; }
#include <bits/stdc++.h> using namespace std; long long forbid[2000001], cost[1000001], last_post[2000001]; long long cal_cost(long long lpower, long long n) { long long i, j, k, lcost = 0; for (i = 0; i < n;) { if (last_post[i + lpower] == i) return 10000000000000; if (forbid[i]) i = last_post[i]; else { i = i + lpower; lcost += cost[lpower]; } } return lcost; } int main() { long long i, j; long long n, m, k; long long min_cost = 10000000000000; scanf("%lld %lld %lld", &n, &m, &k); for (i = 0; i < m; i++) { scanf("%lld", &j); forbid[j] = 1; } for (i = 1; i <= k; i++) scanf("%lld", &cost[i]); if (forbid[0]) { printf("-1"); return 0; } for (i = 0, j = -1; i < n; i++) { if (forbid[i] == 0) j = i; last_post[i] = j; } for (i = n; i <= (n + k); i++) last_post[i] = -1; for (i = 1; i <= k; i++) { min_cost = min(min_cost, cal_cost(i, n)); } if (min_cost >= 10000000000000) printf("-1"); else printf("%lld", min_cost); }
#include <bits/stdc++.h> using namespace std; int n, m, k, s[2000006], a[2000006]; long long res = 1000000000000000007LL; int c[2000006]; void solve() { cin >> n >> m >> k; for (int i = 0; i < m; i++) { int g; cin >> g; s[g] = 1; } if (s[0]) { cout << -1 << '\n'; return; } for (int i = 1; i < k + 1; i++) { cin >> a[i]; } for (int i = 0; i < n + k + 1; i++) { if (s[i] == 0) c[i] = i; else c[i] = c[i - 1]; } for (int l = 1; l < k + 1; l++) { int cur = 0, ans = 0, f = 1; while (cur < n) { if (c[cur + l] == cur) { f = 0; break; } cur = c[cur + l]; ans++; } if (f) res = min(res, 1LL * a[l] * ans); } if (res != 1000000000000000007LL) { cout << res << '\n'; } else { cout << -1 << '\n'; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m, k, cur = 0, ans = 999999999999999; cin >> n >> m >> k; long long b[m], pre[n], c[k + 1]; memset(pre, 0, sizeof(pre)); for (long long i = 0; i < m; i++) { cin >> b[i]; pre[b[i]] = 1; } for (long long i = 1; i <= k; i++) cin >> c[i]; for (long long i = 0; i < n; i++) { if (pre[i] == 0) pre[i] = i; else { if (i == 0) { cout << -1 << endl; exit(0); } else pre[i] = pre[i - 1]; } } long long mx = -999999999999999999; for (long long i = 0; i < n; i++) mx = max(mx, i - pre[i]); mx++; if (mx > k) { cout << -1 << endl; exit(0); } for (long long i = mx; i <= k; i++) { long long ret = 0; long long j = 0; while (j < n) { if (j == pre[j]) { ret += c[i]; j += i; } else j = pre[j]; } ans = min(ret, ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int up = 1e6 + 6; int n, m, k, pos; int cost[up], p[up], last[up]; int main() { scanf("%d", &n); scanf("%d", &m); scanf("%d", &k); for (int i = 1; i <= m; i++) { scanf("%d", &pos); p[pos] = 1; } if (p[0]) { printf("%d\n", -1); return 0; } for (int i = 0; i <= n; i++) { if (!p[i]) last[i] = i; else last[i] = last[i - 1]; } for (int i = 1; i <= k; i++) { scanf("%d", &cost[i]); } long long res = 1ll * up * up; for (int i = 1; i <= k; i++) { int cnt = 1; for (int j = i; j < n; j += i) { if (j - last[j] >= i) { cnt = n + 10; break; } else { j = last[j]; cnt++; } } if (cnt <= n) { res = min(res, 1ll * cnt * cost[i]); } } if (res == 1ll * up * up) { res = -1ll; } printf("%I64d\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, k; bool blocked[1000000]; long long r[1000000]; long long crap; int32_t main() { ios_base::sync_with_stdio(false); scanf("%lld %lld %lld", &n, &m, &k); for (long long i = 0; i < m; ++i) { long long x; scanf("%lld", &x); blocked[x] = true; } if (blocked[0]) { printf("-1\n"); return 0; } long long longestBlock = 0; long long curBlock = 0; for (long long i = 0; i < n; ++i) { if (blocked[i]) { r[i] = r[i - 1]; curBlock++; longestBlock = max(longestBlock, curBlock); } else { r[i] = i; curBlock = 0; } } if (longestBlock + 1 > k) { printf("-1\n"); return 0; } long long res = 1e18; for (long long l = 1; l <= longestBlock; ++l) scanf("%d", &crap); for (long long l = longestBlock + 1; l <= k; ++l) { long long c; scanf("%lld", &c); long long cur = 0; long long i = 0; while (true) { cur += c; if (i + l >= n) break; i = r[i + l]; } res = min(res, cur); } printf("%lld\n", res); }
#include <bits/stdc++.h> using namespace std; vector<long long> blk; long long cvr[1000009], cost[1000009], n, m, k, i, x, kl, minc, last[1000009]; bool pos[1000009]; bool chk = true; long long quant(long long siz) { long long pp = 0, cnt = 1; while (pp + siz < n) { if (last[pp + siz] <= pp) return -1; pp = last[pp + siz]; cnt++; } return cnt; } int main() { cin >> n >> m >> k; for (i = 0; i < n; i++) pos[i] = true; for (i = 0; i < m; i++) { scanf("%lld", &x); if (x == 0) chk = false; blk.push_back(x); pos[x] = false; } for (i = 0; i < k; i++) { scanf("%lld", &cost[i]); } if (chk) { for (i = 0; i < n; i++) { if (pos[i]) last[i] = i; else if (i) last[i] = last[i - 1]; } minc = 1000000000000000000; for (i = 0; i < k; i++) { kl = quant(i + 1); if (kl == -1) continue; minc = min(minc, kl * cost[i]); } } if (chk && minc != 1000000000000000000) cout << minc << endl; else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[1000005], last[1000005]; bool second[1000005]; int n, m, k; int get(int l) { int i = -1, r = 0, res = 0; while (r < n) { if (last[r] <= i) return 1000000007; i = last[r]; r = last[r] + l; ++res; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); int i, x; cin >> n >> m >> k; for (i = 0; i < m; i++) cin >> x, second[x] = 1; for (i = 0; i < k; i++) cin >> a[i]; last[0] = -1; for (i = 0; i < n; i++) { if (second[i] && i) last[i] = last[i - 1]; else if (!second[i]) { last[i] = i; } } long long int ans = (long long int)1e18; for (i = 1; i <= k; i++) { int res = get(i); if (res != 1000000007) { ans = min(ans, (long long int)a[i - 1] * res); } } if (ans == (long long int)1e18) ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int needed(const vector<int>& links, int l) { int ans = 1; for (int curr = 0; curr + l < links.size(); ++ans) { int try_curr = links[curr + l]; if (try_curr == curr) { ans = -1; break; } else { curr = try_curr; } } return ans; } int main() { std::ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; vector<char> ss(n); vector<int> links(n); for (int i = 0; i < m; ++i) { int s; cin >> s; ss[s] = true; } if (ss[0]) { cout << -1; return 0; } for (int i = 1; i < n; ++i) { if (ss[i]) { links[i] = links[i - 1]; } else { links[i] = i; } } vector<long long> costs(k); for (int i = 0; i < k; ++i) { cin >> costs[i]; } long long ans = -1; for (int i = 1; i <= k; ++i) { long long nee = needed(links, i); if (nee != -1) { long long c = costs[i - 1] * nee; if (ans == -1 || c < ans) { ans = c; } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; bool block[1000002] = {false}; long long int count1[1000002] = {0}; int main() { long long int n, m, k; scanf("%lld %lld %lld", &n, &m, &k); long long int x; for (int i = 0; i < m; ++i) { scanf("%lld", &x); block[x] = true; } long long int cost[n + 2]; for (int i = 1; i <= k; ++i) { scanf("%lld", &cost[i]); } long long int mx = -1; for (int i = 0; i < n; i++) { if (block[i]) { count1[i] = 1; if (i) count1[i] += count1[i - 1]; } mx = max(mx, count1[i]); } if (block[0]) { printf("-1"); return 0; } else { long long int ans = 100000000000000; for (int i = mx + 1; i <= k; i++) { long long int ans1 = 100000000000000; int j = 0; while (j < n) { if (block[j]) { j -= count1[j]; } else { if (ans1 == 100000000000000) ans1 = 0; j += i; ans1 += cost[i]; } } ans = min(ans1, ans); } if (ans == 100000000000000) printf("-1"); else printf("%lld", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAX = 2e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, k, x; cin >> n >> m >> k; vector<long long> b(n, 1); for (int i = 0; i < m; i++) { cin >> x; b[x] = 0; } long long seg_l = 0; vector<long long> cs(n, 0); for (int i = 0; i < n; i++) { if (!b[i]) { cs[i] = 1; if (i) cs[i] += cs[i - 1]; } seg_l = max(seg_l, cs[i]); } vector<long long> v(k + 1, 0); for (int i = 1; i <= k; i++) { cin >> v[i]; } if (!b[0]) { cout << "-1" << endl; return 0; } long long ans = 1e18; for (int i = seg_l + 1; i <= k; i++) { long long j = 0; long long cnt = 0; while (j < n) { if (!b[j]) { j -= cs[j]; } else { j += i; cnt += v[i]; } } if (cnt != 0) ans = min(cnt, ans); } if (ans != 1e18) cout << ans << endl; else cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int INF = 1e17; int n, m, k, price[1001010], lst[1001010]; bool blocked[1001010]; long long int getMn(int power) { int at = 0, cnt = 0, atTmp; while (at < n) { atTmp = at; at += power; if (at >= n) return cnt + 1; at = lst[at]; if (at <= atTmp) return INF; cnt++; } return cnt; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int x; cin >> n >> m >> k; for (int i = 0; i < m; i++) { cin >> x; blocked[x] = true; } for (int i = 1; i <= k; i++) cin >> price[i]; if (blocked[0]) { cout << "-1\n"; return 0; } for (int i = 0; i <= n; i++) { if (blocked[i]) lst[i] = lst[i - 1]; else lst[i] = i; } long long int ans = INF; for (int i = 1; i <= k; i++) { long long int aux = getMn(i); if (aux < INF) ans = min(ans, (long long int)price[i] * aux); } if (ans == INF) ans = -1; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, k, a, ans = 1e18; const long long INF = 1e18; const int N = 1e6 + 5; int lst[N], sz[N]; long long cnt(int l) { int r = 0, i = -1; long long rs = 0; while (r < n) { if (lst[r] <= i) return INF; rs++; i = lst[r]; r = lst[r] + l; } return rs; } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < m; i++) { scanf("%d", &a); lst[a] = -1; } if (lst[0] == -1) { cout << -1; return 0; } for (int i = 0; i < k; i++) scanf("%d", &sz[i]); for (int i = 0; i <= n; i++) if (lst[i] != -1) lst[i] = i; else lst[i] = lst[i - 1]; for (int l = 0; l < k; l++) { long long t = cnt(l + 1); if (t != INF) ans = min(ans, t * sz[l]); } ans = (ans == INF) ? -1 : ans; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; int block[m], cost[k + 1]; int region[n]; int nearest[n]; for (int i = 0; i < n; i++) { region[i] = 0; nearest[i] = 0; } for (int i = 0; i < m; i++) { cin >> block[i]; region[block[i]] = 1; } int prev = -1; for (int i = 0; i < n; i++) { if (region[i] == 0) { nearest[i] = i; prev = i; } else nearest[i] = prev; } long long int ans = LLONG_MAX; for (int i = 1; i <= k; i++) { int price; cin >> price; int step = i; int start = 0; long long int total = 0; int flag = 0; while (start < n) { if (region[start] == 0) { total += price; start += step; continue; } if (nearest[start] <= start - step or nearest[start] < 0) { flag = 1; break; } else { total += price; start = nearest[start] + step; } } if (flag == 0) { ans = min(ans, total); } } if (ans == LLONG_MAX) cout << -1 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int64_t rd() { char ch = getchar(); int64_t x = 0; int op = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') op = -1; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * op; } void _wr(int64_t a) { if (a >= 10) _wr(a / 10); putchar(a % 10 + '0'); } void wr(int64_t a, char end = ' ') { if (a < 0) putchar('-'), a = -a; _wr(a); putchar(end); } int64_t divup(int64_t x, int64_t y) { return (x - 1) / y + 1; } int main() { int n = rd(), m = rd(), k = rd(); vector<int> s(n); vector<int> a(k); for (int i = 0; i < m; ++i) s[rd()] = 1; for (int i = 0; i < k; ++i) a[i] = rd(); int blocked = k - 1; int max_block = 0; int prev = -1; for (int i = 0; i < n; ++i) { if (s[i]) { blocked++; s[i] = prev; } else { blocked = 0; s[i] = prev = i; } if (blocked == k) break; if (blocked > max_block) max_block = blocked; } if (blocked == k) { puts("-1"); return 0; } vector<pair<int64_t, int>> min_pos_cost(k - max_block); for (int i = 0; i < min_pos_cost.size(); ++i) { int j = i + max_block; min_pos_cost[i] = {divup(n, j + 1) * a[j], j + 1}; } sort(min_pos_cost.begin(), min_pos_cost.end()); int64_t min = 1000 * 1000 * 1000 * 2000ll; for (auto &c : min_pos_cost) { if (c.first > min) break; int d = c.second; int p = 0; int64_t cnt = 0; while (p < n) { cnt++; p = s[p] + d; } if (cnt * a[d - 1] < min) min = cnt * a[d - 1]; } wr(min, '\n'); }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e14; const int maxn = 1e6 + 5; bool yes[maxn]; int l[maxn]; int a, n, m, k; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; memset(yes, 1, sizeof yes); for (int i = 1; i <= m; i++) { int x; cin >> x; yes[x] = 0; } for (int i = 0; i <= n; i++) { if (yes[i]) l[i] = i; else l[i] = l[i - 1]; } ll ans = inf; for (int i = 1; i <= k; i++) { cin >> a; if (yes[0]) { ll cnt = 1; bool f = 1; int st = 0; while (st < n) { if (st + i >= n) { break; } if (yes[st + i]) { st = st + i; cnt++; } else if (l[st + i] > st) { st = l[st + i]; cnt++; } else { f = 0; break; } } if (f) ans = min(ans, cnt * a); } } if (ans == inf) ans = -1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { char ch = getchar(); int f = 1; t = 0; while ('0' > ch || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } do { (t *= 10) += ch - '0'; ch = getchar(); } while ('0' <= ch && ch <= '9'); t *= f; } const int maxn = 1000010; int n, m, k, mx, cnt[maxn]; bool d[maxn]; long long s[maxn], ans = 1LL << 60; int main() { read(n); read(m); read(k); for (int i = 1; i <= m; i++) { int x; read(x); d[x] = 1; } if (d[0]) { printf("-1\n"); return 0; } for (int i = 0; i < n; i++) { if (!d[i]) continue; cnt[i] = 1; if (i) cnt[i] += cnt[i - 1]; mx = max(mx, cnt[i]); } for (int i = 1; i <= k; i++) read(s[i]); for (int i = 1; i <= k; i++) { int pos = 0, cntcnt = 0; while (pos < n) { if (d[pos]) { if (cnt[pos] == i) break; pos -= cnt[pos]; } else { cntcnt++; pos += i; } } if (pos >= n) ans = min(ans, s[i] * cntcnt); } if (ans >= 1LL << 60) ans = -1; printf("%I64d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long ac[1000005], c[1000005]; bool mk[1000005]; int cpos(int pos, int i) { if (!mk[min(1000005 - 1, pos + i + 1)]) return min(1000005 - 1, pos + i + 1); int p = pos; for (int j = (1 << 19); j; j >>= 1) if (p + j < pos + i + 1 && ac[pos + i + 1] - ac[p + j - 1] < (pos + i + 1 - p - j + 1)) p += j; return p; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k, x; cin >> n >> m >> k; for (int i = 0; i < m; i++) { cin >> x; mk[x] = 1; } if (mk[0]) { cout << (-1) << '\n'; return 0; } for (int i = 0; i < k; i++) cin >> c[i]; ac[0] = mk[0]; for (int i = 1; i < n; i++) ac[i] = ac[i - 1] + mk[i]; long long res = 1e18; for (int i = 0; i < k; i++) { long long cant = 0, pos = 0; while (pos < n) { int xxx = cpos(pos, i) - pos; if (xxx == 0) { cant = -1; break; } pos += xxx; cant++; } if (cant != -1) res = min(res, cant * c[i]); } if (res == 1e18) res = -1; cout << (res) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 123; bool vis[N]; int pre[N]; void load() {} void process() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; ++i) { int pos; scanf("%d", &pos); vis[pos] = 1; } for (int i = 0, j = -1; i < n; ++i) { if (!vis[i]) j = i; pre[i] = j; } long long ans = 1e18; for (int i = 1; i <= k; ++i) { int cost; scanf("%d", &cost); int res = 0; for (int j = 0; j < n; j += i) { if (j - pre[j] >= i || pre[j] == -1) { res = 1e9; break; } j = pre[j]; ++res; } if (res != 1e9) ans = min(ans, 1LL * res * cost); } if (ans != 1e18) printf("%lld", ans); else printf("-1"); return; } int main() { load(); process(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, k; cin >> n >> m >> k; vector<bool> pos(n, false); for (int i = 0; i < m; i++) { long long x; cin >> x; pos[x] = true; } long long mx = 0; long long cur = 0; for (long long i = 0; i < n; i++) { if (!pos[i]) cur = 0; else { cur++; mx = max(mx, cur); } } vector<long long> price(k + 1); for (long long i = 1; i <= k; i++) { long long x; cin >> x; price[i] = x; } if (pos[0] || mx >= k) { cout << "-1"; return 0; } long long prev[n]; prev[0] = 0; for (long long i = 1; i < n; i++) { if (pos[i] == false) prev[i] = i; else prev[i] = prev[i - 1]; } long long ans = 1e15; for (int i = mx + 1; i <= k; i++) { long long s = 0; long long cnt = 0; while (s < n) { cnt++; s = prev[s] + i; } ans = min(ans, cnt * price[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6 + 100; const long long MOD = 1e9 + 7; const long long INF = 1e18; long long cost[MAXN]; bool block[MAXN]; long long le[MAXN]; int main(int argc, char const *argv[]) { long long n, m, p; while (cin >> n >> m >> p) { memset(block, 0, sizeof block); for (long long i = 0; i < m; ++i) { long long tem; scanf("%lld", &tem); block[tem] = 1; } for (long long i = 1; i <= p; ++i) scanf("%lld", &cost[i]); if (block[0]) { puts("-1"); continue; } long long lb = 0, cur = 0; for (long long i = 0; i < n; ++i) { if (block[i]) { cur++; lb = max(lb, cur); le[i] = le[i - 1]; } else { cur = 0; le[i] = i; } } long long ans = INF; for (long long i = lb + 1; i <= p; ++i) { long long cans = 0; for (long long j = 0; j < n; j += i) { if (block[j]) { j = le[j] - i; continue; } cans += cost[i]; } ans = min(ans, cans); } if (ans == INF) { puts("-1"); } else { printf("%lld\n", ans); } } return 0; }
#include <bits/stdc++.h> using namespace std; int bl[3003000]; int ifushf[3003000]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < m; i++) { int a; scanf("%d", &a); bl[a] = 1; } if (bl[0]) { printf("-1\n"); return 0; } ifushf[0] = 0; for (int i = 1; i <= n; i++) { if (bl[i]) ifushf[i] = ifushf[i - 1]; else ifushf[i] = i; } long long ans = (1ll << 60); for (int i = 1; i <= k; i++) { int val; scanf("%d", &val); int t = 0; int pos = 0; while (pos < n) { t++; pos += i; if (pos >= n) break; if (ifushf[pos] <= pos - i) break; pos = ifushf[pos]; } if (pos >= n) ans = min(ans, (long long)val * t); } if (ans != (1ll << 60)) printf("%lld\n", ans); else printf("-1\n"); }
#include <bits/stdc++.h> const long long maxn = 1000010; bool impossible[maxn]; long long cnt[maxn]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); long long n, m, k; std::cin >> n >> m >> k; for (long long i = 1, tmp; i <= m; i++) { std::cin >> tmp; impossible[tmp] = 1; } if (impossible[0]) { std::cout << "-1\n"; return 0; } long long base = 0; for (long long i = 1; i <= n; i++) if (impossible[i - 1]) base = std::max(cnt[i] = cnt[i - 1] + 1, base); else cnt[i] = 0; long long ans = 0x3f3f3f3f3f3f3f3f; for (long long i = 1, val; i <= k; i++) { std::cin >> val; if (i <= base) continue; long long tmp = 0; for (long long j = 1; j <= n; j += i, ++tmp) if (impossible[j - 1]) j -= cnt[j]; ans = std::min(tmp * val, ans); } if (ans == 0x3f3f3f3f3f3f3f3f) std::cout << "-1\n"; else std::cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const long long inf = 1e18; int n, m, k; int s[maxn], a[maxn]; int pos[maxn]; int lst[maxn]; int get_num(int x) { int r = 0, i = -1, res = 0; while (r < n) { if (lst[r] <= i) return -1; else { i = lst[r]; r = lst[r] + x; ++res; } } return res; } int main() { while (scanf("%d%d%d", &n, &m, &k) != EOF) { fill(pos, pos + maxn, 1); memset(lst, 0, sizeof(lst)); for (int i = 0; i < m; i++) scanf("%d", &s[i]); for (int i = 1; i <= k; i++) scanf("%d", &a[i]); for (int i = 0; i < m; i++) pos[s[i]] = 0; if (pos[0] == 0) { printf("-1\n"); continue; } else { for (int i = 1; i < n; i++) { if (pos[i] == 1) lst[i] = i; else lst[i] = lst[i - 1]; } long long mincost = inf; for (int i = 1; i <= k; i++) { int cnt = get_num(i); if (cnt == -1) continue; else { long long ans = (long long)cnt * a[i]; if (mincost > ans) mincost = ans; } } if (mincost == inf) printf("-1\n"); else printf("%I64d\n", mincost); } } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using namespace std; bool is_prime(long long n) { for (long long i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } vector<long long> fact(long long n) { vector<long long> ans; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { ans.push_back(i); while (n % i == 0) { n /= i; } } } if (n > 1) ans.push_back(n); return ans; } long long getPow(long long a, long long b) { long long res = 1ll, tp = a; while (b) { if (b & 1ll) { res *= tp; } tp *= tp; b >>= 1ll; } return res; } long long vec_mult(long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) { return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)); } void ok() { cout << "YES" << endl; exit(0); } void no() { cout << "NO" << endl; exit(0); } inline long long nxt() { long long x; cin >> x; return x; } const long long N = 3000 + 5, inf = 2e16; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); long long n = nxt(), m = nxt(), k = nxt(); vector<long long> used(n, 1); for (int i = 0; i < m; i++) { long long x = nxt(); used[x] = 0; } vector<long long> a(k); for (int i = 0; i < k; i++) { a[i] = nxt(); } if (!used[0]) { return cout << -1, 0; } vector<long long> pos; for (int i = 0; i < n; i++) { if (used[i]) pos.push_back(i); } auto get = [&](long long l) { long long ct = 0; long long start = 0; long long ind = 0; if (!pos.size()) return inf; while (true) { ct++; long long cur = start + l; if (cur >= n) { start = cur; break; } long long cur_ind = (upper_bound(pos.begin(), pos.end(), cur)) - pos.begin(); if (cur_ind == pos.size()) cur_ind--; else if (pos[cur_ind] > cur) { cur_ind--; } if (pos[cur_ind] == start) break; if (cur < n) { start = pos[cur_ind]; } else { start = cur; break; } } if (start >= n) return ct; else return inf; }; long long ans = inf; for (int i = 0; i < k; i++) { long long ct = get(i + 1); if (ct == inf) continue; ans = min(ans, ct * a[i]); } if (ans >= inf) cout << -1; else cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, m, k, s[N], a[N], b[N], c[N]; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; i++) scanf("%d", &s[i]), b[s[i]] = 1; for (int i = 1; i <= k; i++) scanf("%d", &a[i]); if (b[0]) return puts("-1"), 0; c[0] = 0; for (int i = 1; i < n; i++) if (b[i]) c[i] = c[i - 1]; else c[i] = i; long long ans = 1e18; for (int i = 1; i <= k; i++) { int now = 0; long long cnt = 0; while (now < n) { int tmp = now; now += i; cnt++; if (now >= n) break; if (b[now]) now = c[now]; if (c[now] <= tmp) { cnt = (1e12) + 1; break; } } ans = min(ans, cnt * a[i]); } printf("%lld\n", ans <= 1e12 ? ans : -1); return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000000000000; long long n, m, k; vector<long long> dop; void init(long long n) { dop.resize(n + 1); } long long get(long long k) { long long l = 0, alr = 0, last = -1; while (l < n) { if (dop[l] <= last) return inf; last = dop[l]; l = last + k; alr++; } return alr; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; init(n); vector<char> v(n + 1, true); vector<long long> money(k); for (long long c = 0; c < m; c++) { long long e; cin >> e; v[e] = false; } if (!v[0]) { cout << -1; return 0; } dop[0] = 0; for (long long c = 1; c <= n; c++) { if (v[c]) dop[c] = c; else dop[c] = dop[c - 1]; } for (long long c = 0; c < k; c++) cin >> money[c]; long long mmin = inf; for (long long c = 1; c <= k; c++) { long long now = get(c); if (now == inf) continue; mmin = min(mmin, now * money[c - 1]); } cout << (mmin == inf ? -1 : mmin); return 0; }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007LL; const long long int big = 2.19e15 + 1; const long double pai = 3.141592653589793238462643383279502884197; const long double eps = 1e-15; template <class T, class U> void mineq(T& a, U b) { if (a > b) { a = b; } } template <class T, class U> void maxeq(T& a, U b) { if (a < b) { a = b; } } long long int gcd(long long int a, long long int b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return a / gcd(a, b) * b; } template <class T> void SO(T& ve) { sort(ve.begin(), ve.end()); } template <class T> void REV(T& ve) { reverse(ve.begin(), ve.end()); } long long int LBI(vector<int>& ar, int in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } long long int UBI(vector<int>& ar, int in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int i, h, n, m, K; cin >> n >> m >> K; vector<int> doco(n); for (i = 0; i < n; i++) { doco[i] = i; } for (i = 0; i < m; i++) { int s; cin >> s; if (s == 0) { cout << "-1" << endl; return 0; } doco[s] = doco[s - 1]; } long long int ans = big; for (h = 1; h <= K; h++) { long long int gen = 1, bas = 0; while (bas + h < n) { if (doco[bas + h] == bas) { gen = big; break; } bas = doco[bas + h]; gen++; } long long int a; cin >> a; if (gen > n) { continue; } mineq(ans, gen * a); } if (ans == big) { ans = -1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long t = 9000000000000000000; int n, m, k; bool block[10000000]; int cnt[10000000]; int a[10000000]; long long res = t; int main() { cin >> n >> k >> m; for (int i = 0; i < k; i++) { int tem; scanf("%d", &tem); block[tem] = true; } if (block[0]) { cout << "-1" << endl; return 0; } for (int i = 1; i <= m; i++) { scanf("%d", &a[i]); } int max_block = 0; for (int i = 0; i < n; i++) { if (block[i]) cnt[i] = cnt[i - 1] + 1; max_block = max(max_block, cnt[i]); } for (int i = max_block + 1; i <= m; i++) { long long count = 0; int cur = 0; while (cur < n) { if (block[cur]) cur -= cnt[cur]; else { count += a[i]; cur += i; } } res = min(res, count); } if (res >= t) printf("-1\n"); else cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; constexpr int MAXN = 1e6 + 6; constexpr ll INF = 1e18; int n, m, k; int last[MAXN]; int a[MAXN]; int score(int len) { int p = 0; int hops = 0; while (p < n) { p = p + len; ++hops; if (p >= n) return hops; p = last[p]; } return hops; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); scanf(" %d %d %d", &n, &m, &k); for (int i = 0; i <= n; ++i) { last[i] = i; } int x; int max_seg = 0; for (int i = 0; i < m; ++i) { scanf(" %d", &x); if (x == 0) { printf("-1\n"); return 0; } last[x] = last[x - 1]; max_seg = max(max_seg, x - last[x]); } if (max_seg >= k) { printf("-1\n"); return 0; } for (int i = 1; i <= k; ++i) { scanf(" %d", &a[i]); } ll ans = INF; for (int i = max_seg + 1; i <= k; ++i) { int hops = score(i); ans = min(ans, 1LL * a[i] * hops); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000; const long long int inf = 1000ll * 1000 * 1000 * 1000 * 1000; int n, m, k; int block[N]; int price[N + 1]; int last[N]; void read(); void initialize(); long long int ans(); int numberOfLamps(int); int main() { read(); initialize(); cout << ans() << endl; return 0; } void read() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 0; i < m; i++) { int b; cin >> b; block[b] = true; } for (int i = 1; i <= k; i++) cin >> price[i]; } void initialize() { int l = -1; for (int i = 0; i < n; i++) { if (!block[i]) l = i; last[i] = l; } } long long int ans() { if (block[0]) return -1; int con = 0; int maximum = 0; for (int i = 1; i < n; i++) { if (block[i]) con++; else con = 0; maximum = max(maximum, con); } if (k <= maximum) return -1; long long int res = inf; for (int p = maximum + 1; p <= k; p++) { long long int number = numberOfLamps(p); long long int cost = price[p] * number; res = min(res, cost); } return res; } int numberOfLamps(int p) { int number = 0; int lamp = 0; int bound = p; while (bound < n) { number++; lamp = last[bound]; bound = lamp + p; } return number + 1; }
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[1000010]; int blo[1000010]; int ri[1000010]; long long ans; const long long INF = 1e18; long long cal(long long x) { long long r = 0; long long res = 0; while (r < n) { if (ri[r] == -1) return INF; long long tmp = ri[r] + x; res++; if (tmp == r) return INF; r = tmp; } return res; } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i <= n; i++) blo[i] = 1; for (int i = 1; i <= m; i++) { int tmp; scanf("%d", &tmp); blo[tmp] = 0; } for (int i = 1; i <= k; i++) scanf("%d", &a[i]); for (int i = 0; i <= n; i++) { if (blo[i] == 1) ri[i] = i; else { if (i == 0) ri[i] = -1; else ri[i] = ri[i - 1]; } } ans = INF; for (int l = 1; l <= k; l++) { long long tmp = cal(l); if (tmp == INF) continue; ans = min(ans, tmp * a[l]); } if (ans == INF) { printf("-1\n"); return 0; } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; const long long inf = 1e13; int n, m, k, p[N]; long long ans = inf, a[N]; bool is[N]; int main() { cin >> n >> m >> k; for (int i = 1; i <= m; i++) { int x; scanf("%d", &x); is[x] = 1; } for (int i = 1; i <= k; i++) scanf("%lld", &a[i]); if (is[0] == 1) { cout << -1 << endl; return 0; } for (int i = 0; i < n; i++) { p[i] = (is[i]) ? p[i - 1] : i; } for (int i = 1; i <= k; i++) { long long cnt = 0, t = 0; bool can = 1; while (t < n) { if (p[t] + i <= t) { can = 0; break; } cnt++; t = p[t] + i; } if (can) ans = min(ans, cnt * a[i]); } cout << ((ans < inf) ? ans : -1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string)s); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto& x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } const long double eps = 1e-12; const int N = 1e6 + 9; int cnt, mx, a[N], b[N]; bool bloc[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < m; i++) { cin >> b[i]; bloc[b[i]] = 1; } for (int i = 1; i <= k; i++) { cin >> a[i]; } vector<int> ss; for (int i = 0; i < n; i++) { if (bloc[i] == 1) cnt++; else { ss.push_back(-i); mx = max(mx, cnt); cnt = 0; } } sort(ss.begin(), ss.end()); mx = max(mx, cnt); long long ans = 1e18; if (mx >= k || bloc[0]) return cout << "-1\n", 0; for (int i = mx + 1; i <= k; i++) { cnt = 0; for (int j = 0; j < n;) { if (bloc[j]) { j = -(*upper_bound(ss.begin(), ss.end(), -j)); } else { j += i; cnt++; } } ans = min(ans, 1ll * cnt * a[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O2") const int MAXN = 1e6 + 5; const int mod = 1e9 + 7; using namespace std; int n, m, k, pre[MAXN]; bool s[MAXN]; long long a[MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i = 0; i < m; i++) { int c; cin >> c; s[c] = 1; } for (int i = 1; i <= k; i++) cin >> a[i]; if (s[0]) { cout << -1; return 0; } s[n] = 0; pre[0] = 0; for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1]; if (!s[i]) pre[i] = i; } long long ans = -1; for (int i = 1; i <= k; i++) { long long loc = 0; int p = 0; bool can = 1; while (can) { p += i; loc += a[i]; p = min(p, n); if (p == n) break; int t = pre[p]; if (t + i <= p) can = 0; p = t; } if (!can) continue; ans = min(ans, loc); if (ans == -1) ans = loc; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; long long pos[1000005], dp[1000005], a[1000005], ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n, m, k, i, j; cin >> n >> m >> k; for (i = 0; i < m; i++) { long long x; cin >> x; pos[x] = 1; } for (i = 1; i <= k; i++) cin >> a[i]; if (pos[0] == 1) { cout << -1; return 0; } for (i = 0; i < n; i++) { if (pos[i] == 0) dp[i] = i; else dp[i] = dp[i - 1]; } ans = 1e18; for (i = 1; i <= k; i++) { long long curr = 0, temp = 0, c = 0; while (curr < n) { if (pos[curr] == 0) { curr += i; temp++; } else { if (dp[curr] == curr - i) { c = 1; break; } else curr = dp[curr]; } } if (c == 0) ans = min(ans, temp * a[i]); } if (ans == 1e18) cout << -1; else cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; bool block[1000005]; int blockst[1000005]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<int> blocked(m); int len = 1; int mxlen = 1; if (m == 0) { mxlen = 0; } for (int i = 0; i < m; i++) { cin >> blocked[i]; block[blocked[i]] = true; if (i > 0) { if (blocked[i] - blocked[i - 1] == 1) { len++; blockst[blocked[i]] = blockst[blocked[i - 1]]; if (len >= k) { cout << -1; return 0; } mxlen = max(mxlen, len); } else { blockst[blocked[i]] = blocked[i] - 1; len = 1; } } else { blockst[blocked[i]] = blocked[i] - 1; } } if (block[0]) { cout << -1; return 0; } vector<long long int> costs(k + 1); for (int i = 1; i <= k; i++) { cin >> costs[i]; } long long int mncost = 9223372036854775807LL; for (int siz = mxlen + 1; siz <= k; siz++) { long long int used = 0; for (int pos = 0; pos < n; pos += siz) { if (block[pos]) { pos = blockst[pos]; } used += costs[siz]; if (used >= mncost) { break; } } mncost = min(mncost, used); } if (mncost == 9223372036854775807LL) { cout << -1; return 0; } cout << mncost; return 0; }
#include <bits/stdc++.h> int k, n, m; long long ans, temp; int p[3000000]; int a[3000000]; int main() { scanf("%d %d %d", &n, &m, &k); int pos; for (int i = 1; i <= m; ++i) { scanf("%d", &pos); p[pos] = -1; } for (int i = 1; i <= k; ++i) scanf("%d", &a[i]); pos = -1; for (int i = 0; i <= n + k + 2; ++i) { if (p[i] == 0) pos = i; p[i] = pos; } ans = 1LL << 61; for (int i = 1; i <= k; ++i) { temp = 0; pos = p[0]; temp = 0; if (pos < 0) break; while (pos < n) { temp += a[i]; if (p[pos + i] <= pos) break; pos = p[pos + i]; } if (pos >= n && temp < ans) ans = temp; } if (ans > 1LL << 60) ans = -1; printf("%I64d\n", ans); return 0; }