#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
void solve()
{
ll n, k, h, c, ans = 0, mnh, mnc, mn = 1e18;
cin >> n >> k;
vector<ll> cnt(1002);
cin >> mnh >> mnc;
for (int i = 2; i <= n; i++)
{
cin >> h >> c;
if (h == mnh)
{
ans += k;
h++;
}
cnt[h]++;
}
for (int i = 300; i >= 0; i--)
{
for (int j = mnh + 1; j <= 1000; j++)
{
ll temp = max(0ll, cnt[j] - i);
cnt[j] -= temp;
cnt[j + 1] += temp;
ans += k * temp;
}
mn = min(mn, ans + max(0ll, mnc * (i - 1)));
}
cout << mn << '\n';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tests = 1;
// cin >> tests;
for (int i = 1; i <= tests; i++)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |