#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() {
ll n, p;
cin >> n >> p;
vector<monster> monsters(n);
for (monster& m : monsters) {
ll a, d;
cin >> a >> d;
m = { a, (d + 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 | 1684 KiB | ||||
2 | Accepted | 3ms | 1848 KiB | ||||
subtask2 | 0/13 | ||||||
3 | Accepted | 3ms | 2196 KiB | ||||
4 | Wrong answer | 3ms | 2404 KiB | ||||
5 | Wrong answer | 3ms | 2608 KiB | ||||
6 | Accepted | 3ms | 2700 KiB | ||||
subtask3 | 0/22 | ||||||
7 | Accepted | 3ms | 2916 KiB | ||||
8 | Wrong answer | 3ms | 3248 KiB | ||||
9 | Accepted | 3ms | 3260 KiB | ||||
10 | Wrong answer | 3ms | 3100 KiB | ||||
11 | Wrong answer | 3ms | 3100 KiB | ||||
12 | Wrong answer | 3ms | 3104 KiB | ||||
13 | Wrong answer | 3ms | 3108 KiB | ||||
14 | Wrong answer | 3ms | 3352 KiB | ||||
subtask4 | 0/65 | ||||||
15 | Accepted | 72ms | 7628 KiB | ||||
16 | Wrong answer | 61ms | 8636 KiB | ||||
17 | Accepted | 74ms | 9888 KiB | ||||
18 | Wrong answer | 74ms | 11112 KiB | ||||
19 | Wrong answer | 74ms | 12344 KiB | ||||
20 | Wrong answer | 74ms | 13376 KiB | ||||
21 | Wrong answer | 72ms | 14324 KiB | ||||
22 | Wrong answer | 72ms | 15676 KiB | ||||
23 | Wrong answer | 71ms | 17024 KiB | ||||
24 | Wrong answer | 72ms | 18248 KiB |