Submission #1341446

#TimeUsernameProblemLanguageResultExecution timeMemory
1341446alexddSki 2 (JOI24_ski2)C++20
42 / 100
2094 ms2088 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int MAXN = 305;
int n,k,cate;
pair<int,int> v[305];
int dp[2][MAXN][MAXN];
int invc[305];

map<int,int> nrm;
map<int, vector<int>> ofh;

void chmin(int&x, int y)
{
    x = min(x, y);
}

signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>k;
    int maxh = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].first>>v[i].second;
        maxh = max(maxh, v[i].first);
        nrm[v[i].second]++;
        ofh[v[i].first].push_back(i);
    }
    //assert(maxh <= 300);
    maxh += n;//-----------------------------------------------------------------------------------------------------------

    for(auto&it:nrm)
    {
        it.second = ++cate;
        invc[cate] = it.first;
    }
    cate++;
    invc[cate] = INF;

    for(int cnt=0;cnt<=n;cnt++)
        for(int free=0;free<=n+1;free++)
            dp[1][cnt][free] = INF;

    int minc = cate;
    dp[1][0][1] = 0;
    for(int h=0;h<=maxh;h++)
    {
        int pas = h%2;

        int cur = ofh[h].size(), mincur = cate;
        for(int id:ofh[h])
            mincur = min(mincur, nrm[v[id].second]);
        int newmin = min(minc, mincur);
        for(int cnt=0;cnt<=n;cnt++)
            for(int free=0;free<=n+1;free++)
                dp[pas][cnt][free] = INF;

        for(int cnt=1;cnt<=n;cnt++)
            for(int free=0;free<=n+1;free++)
                dp[1-pas][cnt][free] = min(dp[1-pas][cnt][free], dp[1-pas][cnt-1][free]);


        for(int cnt=0;cnt<=n;cnt++)
        {
            for(int free=0;free<=n+1;free++)
            {
                if(dp[1-pas][cnt][free] == INF || minc == cate)
                    continue;
                for(int dif = -cnt; dif < cur - free; dif++)
                {
                    chmin(dp[pas][cnt + dif][cur - dif], dp[1-pas][cnt][free] + (cur - dif - free) * invc[minc] + (cnt + dif) * k);
                }
            }
        }

        for(int cnt=0;cnt<=n;cnt++)
        {
            for(int free=0;free<=n+1;free++)
            {
                int lim = min(n, cnt + free - cur);
                if(lim >= 0) chmin(dp[pas][cnt][free], dp[1-pas][lim][free] + cnt * k);

                //if(cnt >= 1) dp[pas][cnt][free] = min(dp[pas][cnt][free], dp[pas][cnt-1][free]);
            }
        }

        minc = newmin;
    }
    int rez = INF;
    for(int free=0;free<=n+1;free++)
        rez = min(rez, dp[maxh%2][0][free]);
    assert(rez != INF);
    cout<<rez;
    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...