Source Code
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll N = 1000001;

int main() {
    ll n, k;
    cin >> n >> k;

    vector<pll> a;
    for (int i = 0; i < n; i++) {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        if (x <= N) {
            a.emplace_back(y, x);
        }
    }
    sort(a.begin(), a.end());

    ll old = 0;
    ll answer = 0;
    for (pll p : a) {
        ll x = p.second * p.second;
        ll current = k / x + old + old / x;
        ll now = current - old;
        answer += now * p.first;
        old = current;
    }

    cout << answer << endl;
}
Copy
Number of the Beast Baraa_Armoush
GNU G++17
3 ms
868 KB
Wrong Answer