#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[]{ -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[]{ 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
#else
#endif
}
int main() {
run();
int n;
ll k;
cin >> n >> k;
vector<pair<ll, int>> v;
for (int i = 0; i < n; i++) {
ll p;
int c;
cin >> p >> c;
if (p <= k/p)
v.push_back({ c,p * p });
}
ll total = 0;
for (auto& it : v)
total += it.first * (k / it.second);
sort(all(v));
ll cnt = 0;
for (auto& it : v) {
total -= it.first * (cnt / it.second);
cnt += (k / it.second);
}
cout << total << endl;
}
Copy