제출 #1181312

#제출 시각아이디문제언어결과실행 시간메모리
1181312trashaccountSki 2 (JOI24_ski2)C++20
5 / 100
31 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define isz(a) (int)(a).size()

const int NM = 300, inf = 1e18;

int N, K, H[NM+5], C[NM+5], tmpH[NM+5], tmpC[NM+5];
vector <int> od;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> K;
    for (int i = 1; i <= N; i++)
        cin >> H[i] >> C[i];
    if (N == 1){
        cout << "0\n";
        return 0;
    }
    
    int ans = +inf;
    for (int i = 1; i <= N; i++){
        int res = 0;
        for (int j = 1; j <= N; j++){
            tmpC[j] = 0;
            if (j == i){
                tmpH[j] = H[j];
                continue;
            }
            tmpH[j] = max(H[i]+1, H[j]);
            res += (tmpH[j]-H[j])*K;
        }
        od.clear();
        for (int j = 1; j <= N; j++) od.push_back(j);
        sort(od.begin(), od.end(), [&](int x, int y){
            return tmpH[x] < tmpH[y];
        });
        for (int j = 1; j < isz(od); j++){
            int kbest = -1;
            for (int k = 0; k < j; k++){
                if (tmpH[od[k]] == tmpH[od[j]]) break;
                if (kbest == -1 || tmpC[od[k]] < tmpC[od[kbest]]){
                    kbest = k;
                }
            }
            res += tmpC[od[kbest]];
            if (tmpC[od[kbest]] == 0){
                tmpC[od[kbest]] = C[od[kbest]];
            }
        }
        ans = min(ans, res);
    }
    cout << ans;
    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...