// https://www.lanqiao.cn/problems/19703/learning/?page=1&first_category_id=1&name=%E8%AE%AD%E7%BB%83%E5%A3%AB%E5%85%B5
#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
ll n, S, ans = 0;
map<ll, ll, greater<ll>> l;
vector<PLL> ps(N);
int main() {
cin >> n >> S;
for (ll i = 0; i < n; i++) {
ll p, c;
cin >> p >> c;
l[c] += p;
}
ll ii = 0;
for (auto i: l) {
if (!ii) ps[ii] = {i.first, i.second};
else ps[ii] = {i.first, ps[ii - 1].second + i.second};
ii++;
}
ll cntS = 0;
for (ll i = 0; i < ps.size(); i++)
if (ps[i].second >= S) {
ans += ps[i].first * S;
cntS = ps[i].first;
break;
}
for (ll i = 0; i < ps.size(); i++)
if (ps[i].first - cntS <= 0) break;
else if (!i) ans += (ps[i].first - cntS) * ps[i].second;
else ans += (ps[i].first - cntS) * (ps[i].second - ps[i - 1].second);
cout << ans << endl;
return 0;
}
1 回复
0 转发
0 喜欢
1 阅读



