# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1021204 | amunduzbaev | Ski 2 (JOI24_ski2) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef long long ll;
#define int ll
const int inf = 1e9;
const ll INF = 1e15;
const int N = 305;
ll dp[2][N][N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
vector<int> h(n), c(n);
for(int i=0;i<n;i++){
cin >> h[i] >> c[i];
}
vector<int> p(n);
iota(p.begin(), p.end(), 0);
sort(p.begin(), p.end(), [&](int i, int j){
if(h[i] != h[j]) return h[i] < h[j];
else return c[i] < c[j];
});
memset(dp, 63, sizeof dp);
//~ cout<<"here"<<endl;
dp[0][0][1] = 0;
int t = 0, s = 1;
ll mn = INF;
//~ const int MX = N + N;
vector<int> H = h;
sort(H.begin(), H.end());
for(int i=1;i<n;i++){
if(H[i] <= H[i - 1]) H[i] = H[i - 1] + 1;
}
int i = 0;
for(auto h_ : H){
int j = i;
while(j < n && h[p[j]] == h_){
j++;
}
memset(dp[s], 63, sizeof dp[s]);
int cur = j - i;
for(int c=0;c<=i;c++){
for(int cnt=0;cnt<=i+1;cnt++){
if(dp[t][c][cnt] >= INF) continue;
for(int x=min(cnt, c + cur);x<=c + cur;x++){
dp[s][c + cur - x][max(cnt, x)] = min(dp[s][c + cur - x][max(cnt, x)], dp[t][c][cnt] + max(0ll, x - cnt) * 1ll * mn + (c + cur - x) * 1ll * k);
}
}
}
swap(s, t);
while(i < j){
mn = min(mn, 1ll * c[p[i]]);
i++;
}
}
mn = INF;
for(int i=0;i<=n;i++){
mn = min(mn, dp[t][0][i]);
}
//~ cout<<dp[t][0][
cout<<mn<<"\n";
}