#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ari2 = array<int, 2>;
using ari3 = array<int, 3>;
using arl2 = array<ll, 2>;
using arl3 = array<ll, 3>;
template <class T> using vt = vector<T>;
#define all(x) begin(x), end(x)
#define size(x) (int((x).size()))
#define REP(a,b,c,d) for(int a=(b);(d)>0?a<=(c):a>=(c);a+=(d))
#define FOR(a,b,c) REP(a,b,c,1)
#define ROF(a,b,c) REP(a,b,c,-1)
template <class T, class U> T &chmin(T &a, const U &b) { a = a < b ? a : b; return a; }
signed main() {
#ifndef DEBUG
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int N, K;
cin >> N >> K;
vt<int> H(N), C(N), hh = {-1};
FOR(i, 0, N - 1) {
cin >> H[i] >> C[i];
hh.push_back(H[i]);
}
sort(all(hh));
FOR(i, 1, size(hh) - 1)
hh[i] = max(hh[i], hh[i - 1] + 1);
hh.push_back(hh.back() + 1);
vt<int> cnt(size(hh));
vt<ll> min_C(size(hh), (ll)1e15);
FOR(i, 0, N - 1) {
const int j = lower_bound(all(hh), H[i]) - hh.begin();
cnt[j]++, chmin(min_C[j], C[i]);
}
vt<vt<ll>> dp(N + 1, vt<ll>(N + 1, (ll)1e15)), dp2;
dp[0][1] = 0;
ll min_c = 1e15;
FOR(hi, 1, size(hh) - 1) {
dp2.assign(N + 1, vt<ll>(N + 1, (ll)1e15));
FOR(i, 0, N)
FOR(j, 0, N)
if (dp[i][j] < 1e15 && __int128(hh[hi] - hh[hi - 1]) * i * K < 1e15)
chmin(dp2[min(N, max(i + cnt[hi] - j, 0))][j], dp[i][j] + 1ll * (hh[hi] - hh[hi - 1]) * i * K);
chmin(min_c, min_C[hi]);
FOR(i, 0, N)
FOR(j, 0, N - 1)
chmin(dp2[i][j + 1], dp2[i][j] + min_c);
swap(dp, dp2);
}
cout << *min_element(all(dp[0])) << '\n';
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |