제출 #1337416

#제출 시각아이디문제언어결과실행 시간메모리
1337416franuchSki 2 (JOI24_ski2)C++20
0 / 100
4 ms456 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;

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

void solve() {
	sort(all(a), [](auto &p, auto &q) {
		if (p.h != q.h)
			return p.h < q.h;
		return p.c < q.c;
	});
	ll pre = 0;
	for (ll i = 1; i < n; i++)
		if (a[i].h == a[0].h) {
			a[i].h++;
			pre += X;
		}

	ll ans = INF;
	for (ll k = 1; k < n; k++) {
		ll x = 0;
		x += (k - 1) * a[0].c;
		multiset<ll> end;
		for (ll i = 1; i < 1 + k; i++)
			end.insert(a[i].h);
		for (ll i = 1 + k; i < n; i++) {
			ll f = *end.begin();
			x += (f + 1 - a[i].h) * X;
			end.erase(end.begin());
			end.insert(f + 1);
		}
		ans = min(ans, x);
	}
	cout << pre + 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...