제출 #1337385

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

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 ans = 0;
	for (ll i = 1; i < n; i++)
		if (a[i].h == a[0].h) {
			a[i].h++;
			ans += X;
		}

	ll bf = a[0].c;
	ll mn = a[0].c;
	deque<ll> fr;
	fr.pub(a[0].h);
	for (ll i = 1; i < n; i++) {
		if (a[i].h != a[i - 1].h)
			mn = min(mn, bf);
		if (not fr.empty() and fr.front() < a[i].h)
			fr.pop_front();
		else
			ans += mn;
		fr.pub(a[i].h);
		bf = min(bf, a[i].c);
	}
	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...