36102023-03-01 10:16:35Error42Szörnyekcpp17Accepted 100/10034ms6936 KiB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

using ll = long long;

struct monster {
    ll attack;
    ll hits;

    bool operator <(monster const& rhs) const {
        return attack * rhs.hits < rhs.attack * hits;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll n, p;
    cin >> n >> p;

    vector<monster> monsters(n);

    for (monster& m : monsters) {
        ll a, d;
        cin >> a >> d;

        m = { d, (a + p - 1) / p };
    }

    sort(monsters.begin(), monsters.end());

    ll ans = 0;
    ll dmg = 0;

    for (monster const& m : monsters) {
        dmg += m.attack;

        ans += dmg * m.hits;
    }

    ans -= dmg;

    cout << ans << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2056 KiB
subtask213/13
3Accepted3ms2376 KiB
4Accepted3ms2476 KiB
5Accepted2ms2508 KiB
6Accepted3ms2496 KiB
subtask322/22
7Accepted3ms2504 KiB
8Accepted3ms2528 KiB
9Accepted3ms2724 KiB
10Accepted3ms2812 KiB
11Accepted3ms2952 KiB
12Accepted3ms3088 KiB
13Accepted3ms3196 KiB
14Accepted3ms3420 KiB
subtask465/65
15Accepted32ms6284 KiB
16Accepted28ms6588 KiB
17Accepted27ms6432 KiB
18Accepted34ms6428 KiB
19Accepted34ms6432 KiB
20Accepted34ms6484 KiB
21Accepted34ms6624 KiB
22Accepted34ms6664 KiB
23Accepted30ms6936 KiB
24Accepted32ms6772 KiB