Submission #1012088

#TimeUsernameProblemLanguageResultExecution timeMemory
1012088huutuanSki 2 (JOI24_ski2)C++14
12 / 100
547 ms467032 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N=310, inf=1e18; int n, z, f[N*2][N][N], c[N*2], cnt[N*2]; pair<int, int> a[N]; vector<int> vals; int d[N*2]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> z; map<int, int> mp; for (int i=1; i<=n; ++i){ cin >> a[i].first >> a[i].second; ++a[i].first; ++mp[a[i].first]; } { int open=1, cur=0; for (auto &i:mp){ cur=max(0ll, cur+i.second-open); vals.push_back(i.first); int _open=open, _cur=cur, pos=i.first; while (cur){ ++pos; cur=max(0ll, cur-open); vals.push_back(pos); } open=_open, cur=_cur; } } vals.push_back(0); sort(vals.begin(), vals.end()); vals.resize(unique(vals.begin(), vals.end())-vals.begin()); for (int i=1; i<=n; ++i) a[i].first=lower_bound(vals.begin(), vals.end(), a[i].first)-vals.begin(), ++cnt[a[i].first]; for (int i=0; i<(int)vals.size()-1; ++i) d[i]=vals[i+1]-vals[i]; for (int i=0; i<N*2; ++i) c[i]=inf; for (int i=1; i<=n; ++i) c[a[i].first+1]=min(c[a[i].first+1], a[i].second); for (int i=1; i<N*2; ++i) c[i]=min(c[i], c[i-1]); for (int i=0; i<N*2; ++i) for (int j=0; j<N; ++j) for (int k=0; k<N; ++k) f[i][j][k]=inf; f[0][1][0]=0; for (int i=0; i<N*2-1; ++i) for (int j=0; j<=n; ++j) for (int k=0; k<=n; ++k) if (f[i][j][k]!=inf){ for (int x=min(cnt[i+1]+k, j); x<=cnt[i+1]+k; ++x){ if (c[i+1]==inf && x-j>0) continue; f[i+1][max(j, x)][k+cnt[i+1]-x]=min(f[i+1][max(j, x)][k+cnt[i+1]-x], f[i][j][k]+max(0ll, x-j)*c[i+1]+(k+cnt[i+1]-x)*z*d[i]); } } int ans=inf; for (int i=0; i<=n; ++i) ans=min(ans, f[(int)vals.size()-1][i][0]); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...