/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 300+100, M = 1e5+10, K = 52, MX = 30;
const ll INF = 1e18;
int n;
ll k, p[N], dp[N][N][N], mn[N];
array<ll, 2> a[N], b[N];
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; ++i){
cin >> a[i][0] >> a[i][1];
}
ll ans = INF;
int m = 100;
for(int hotel = 1; hotel <= 1; ++hotel){
ll init_cost = 0;
for(int i = 1; i <= n; ++i){
b[i][1] = a[i][1];
}
for(int i = 0; i <= m; ++i) p[i] = 0, mn[i] = INF;
for(int i = 1; i <= n; ++i){
if(i == hotel){
// nothing
b[i][0] = a[i][0];
p[b[i][0]]++;
mn[b[i][0]] = min(mn[b[i][0]], b[i][1]);
}else{
init_cost += max(0ll, (a[hotel][0] - a[i][0] + 1) * k);
b[i][0] = max(a[i][0], a[hotel][0] + 1);
p[b[i][0]]++;
mn[b[i][0]] = min(mn[b[i][0]], b[i][1]);
}
}
for(int i = 1; i <= m; ++i) p[i] += p[i - 1], mn[i] = min(mn[i], mn[i - 1]);
for(int h = 0; h <= m; ++h){
for(int i = 0; i <= n; ++i){
for(int l = 0; l <= n; ++l) dp[h][i][l] = INF;
}
}
sort(b+1, b+1+n);
dp[b[1][0]][0][1] = 0;
for(int h = b[1][0] + 1; h <= b[n][0] + n; ++h){
for(int j = 0; j <= p[h - 1]; ++j){
for(int i = 0; i <= p[h] - p[h - 1] + j; ++i){
int sz = p[h] - p[h - 1] + j - i;
for(int mx = 1; mx <= n; ++mx){
dp[h][i][max(mx, sz)] = min(dp[h][i][max(mx, sz)], dp[h - 1][j][mx] + max(0ll, (sz - mx) * mn[h - 1]) + i * k);
}
}
}
}
// for(int i = 1; i <= n; ++i){
// cout << b[i][0] << ' ' << b[i][1] << '\n';
// }
ll min_dp = INF;
for(int h = b[n][0]; h <= b[n][0] + n; ++h){
for(int mx = 1; mx <= n; ++mx) min_dp = min(min_dp, dp[h][0][mx]);
}
ans = min(ans, min_dp + init_cost);
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
# | 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... |