제출 #1341452

#제출 시각아이디문제언어결과실행 시간메모리
1341452alexddSki 2 (JOI24_ski2)C++20
42 / 100
250 ms2652 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int MAXN = 305;
int n,k;
pair<int,int> v[305];
int dp[2][MAXN][MAXN];
int auxdp[MAXN][MAXN];

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);
        ofh[v[i].first].push_back(i);
    }
    //assert(maxh <= 300);
    maxh += n;//-----------------------------------------------------------------------------------------------------------


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

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

        int cur = ofh[h].size(), mincur = INF;
        for(int id:ofh[h])
            mincur = min(mincur, 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;
                if(cnt >= 1) dp[1-pas][cnt][free] = min(dp[1-pas][cnt][free], dp[1-pas][cnt-1][free]);

                auxdp[cnt][free] = INF;
                if(minc < INF)
                {
                    if(dp[1-pas][cnt][free] != INF) auxdp[cnt][free] = dp[1-pas][cnt][free] - free * minc;
                    if(free >= 1) auxdp[cnt][free] = min(auxdp[cnt][free], auxdp[cnt][free-1]);
                }
            }

        if(minc < INF)
        {
            for(int x=0;x<=n;x++)
            {
                for(int cnt=0;cnt<=n;cnt++)
                {
                    //x = cnt + dif
                    int dif = x - cnt;
                    assert(-cnt <= dif);
                    //for(int free=0;free<cur-dif;free++)
                       // chmin(dp[pas][x][cur - dif], dp[1-pas][cnt][free] - free * minc + (cur - dif) * minc + x * k);
                    if(cur - dif - 1 >= 0)
                        chmin(dp[pas][x][cur - dif], auxdp[cnt][cur - dif - 1] + (cur - dif) * minc + x * 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);
            }
        }

        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...