Submission #1337429

#TimeUsernameProblemLanguageResultExecution timeMemory
1337429franuchSki 2 (JOI24_ski2)C++20
0 / 100
2094 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define vc vector
#define st first
#define nd second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)a.size()
#define pub push_back
#define pob pop_back
ll INF = 1e18;

struct P {
	ll h, c;
};

ll n, X;
vc<P> a;
ll ans = INF;
vc<ll> par = {-1};

void input() {
	cin >> n >> X;
	a.resize(n);
	for (ll i = 0; i < n; i++)
		cin >> a[i].h >> a[i].c;
}

void rec(ll i = 1) {
	if (i == n) {
		ll x = 0;
		vc<ll> h(n), d(n, -1);
		h[0] = a[0].h;
		for (ll j = 1; j < n; j++)
			d[par[j]]++;
		for (ll j = 1; j < n; j++)
			for (ll k = 1; k < n; k++)
				h[k] = max(max(h[k], a[k].h), h[par[k]] + 1);
		for (ll j = 0; j < n; j++) {
			x += max(0ll, d[j]) * a[j].c;
			x += (h[j] - a[j].h) * X;
		}
		ans = min(ans, x);
		return;
	}
	for (ll p = 0; p < n; p++) {
		if (p == i)
			continue;
		par.pub(p);
		rec(i + 1);
		par.pob();
	}
}

void solve() {
	sort(all(a), [](auto &p, auto &q) {
		if (p.h != q.h)
			return p.h < q.h;
		return p.c < q.c;
	});
	rec();
	cout << ans << "\n";
}

void program() {
	input();
	solve();
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	program();
	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...