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
Test Case #1
0 ms
276 KB
Accepted
Input
4 10
2 300
3 66
5 100
13 32
Output
666
Judge Output
666
Checker Message
1 number(s): "666"
Test Case #2
0 ms
416 KB
Accepted
Input
2 50
3 10
7 21
Output
71
Judge Output
71
Checker Message
1 number(s): "71"
Test Case #3
3 ms
868 KB
Wrong Answer
Input
8944 1000000000000
530851 634109
437629 135449
760841 608005
987979 505317
567187 797505
115057 581792
986287 132112
788677 472337
209929 417283
972313 694722
65809 400083
710887 970135
432959 268565
920039 761441
375703 505835
988439 938996
257473 ...
Output
39181317758384
Judge Output
39179400996329
Checker Message
1st numbers differ - expected: '39179400996329', found: '39181317758384'