제출 #1129477

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

#define ff first
#define ss second
#define bl ' '
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define comp(v) (v).erase(unique(all(v)), (v).end())
#define lbd(v,x) lower_bound(all(v), (x))-(v).begin()
#define ubd(v,x) upper_bound(all(v), (x))-(v).begin()

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<int, pi> ipi;
typedef pair<pi, pi> pipi;
typedef pair<ll, ll> pll;

const int MAXN = 330;//100100*20;
const ll MOD = 1e9+7;
const ll INF = 2e18;

struct Point {
    ll h, c;
}arr[MAXN];

vector<int> v;
ll dp[MAXN][MAXN*2], mn[MAXN], k;
int cnt[MAXN];

ll solve(int idx, int h, int rem) {
    if(dp[idx][h-rem+MAXN] != -1) return dp[idx][h-rem+MAXN];
    if(idx == v.size()) return 0;

    ll &res = dp[idx][h-rem+MAXN];
    if(h <= rem) {
        return res = solve(idx+1, cnt[idx+1], rem);
    }

    res = LLONG_MAX;
    for(int i=0; i<=h-rem; i++) {
        res = min(res, solve(idx+1, cnt[idx+1]+i, h-i)+k*i+mn[idx-1]*(h-rem-i));
    }

    return res;
}

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

    int n; cin>>n>>k;
    for(int i=0; i<n; i++) cin>>arr[i].h>>arr[i].c;

    sort(arr, arr+n, [&](Point &a, Point &b) {
        return a.h!=b.h?a.h<b.h:a.c<b.c;
    });

    ll h = arr[0].h; mn[0] = arr[0].c; int x = 0;
    for(int i = 0, idx = 0; i < n; i++) {
        v.push_back(h);
        while(idx < n && arr[idx].h == h) x++, idx++;
        x--;
        h = max(arr[i+1].h, h+1);
    }

    mn[0] = INT_MAX;
    for(int i = 0, idx = 0; i < n; i++) {
        while(idx < n && arr[idx].h == v[i]) {
            cnt[i]++; mn[i]=min(mn[i], arr[idx].c);
            idx++;
        }

        mn[i+1] = mn[i];
    }

    memset(dp, -1, sizeof dp);
    cout << solve(1, cnt[1]+cnt[0]-1, 1)+k*(cnt[0]-1);
}
#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...