#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";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
subtask2 | 13/13 | ||||||
3 | Accepted | 3ms | 2376 KiB | ||||
4 | Accepted | 3ms | 2476 KiB | ||||
5 | Accepted | 2ms | 2508 KiB | ||||
6 | Accepted | 3ms | 2496 KiB | ||||
subtask3 | 22/22 | ||||||
7 | Accepted | 3ms | 2504 KiB | ||||
8 | Accepted | 3ms | 2528 KiB | ||||
9 | Accepted | 3ms | 2724 KiB | ||||
10 | Accepted | 3ms | 2812 KiB | ||||
11 | Accepted | 3ms | 2952 KiB | ||||
12 | Accepted | 3ms | 3088 KiB | ||||
13 | Accepted | 3ms | 3196 KiB | ||||
14 | Accepted | 3ms | 3420 KiB | ||||
subtask4 | 65/65 | ||||||
15 | Accepted | 32ms | 6284 KiB | ||||
16 | Accepted | 28ms | 6588 KiB | ||||
17 | Accepted | 27ms | 6432 KiB | ||||
18 | Accepted | 34ms | 6428 KiB | ||||
19 | Accepted | 34ms | 6432 KiB | ||||
20 | Accepted | 34ms | 6484 KiB | ||||
21 | Accepted | 34ms | 6624 KiB | ||||
22 | Accepted | 34ms | 6664 KiB | ||||
23 | Accepted | 30ms | 6936 KiB | ||||
24 | Accepted | 32ms | 6772 KiB |