#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX(a, b) (a) = max((a), (b))
#define MIN(a, b) (a) = min((a), (b))
#define all(a) (a).begin(), (a).end()
#define sortedpair(a, b) {min((a), (b)), max((a), (b))}
const ll MOD = 1e9+7;
void solve(){
ll n, p; cin>>n>>p;
vector<pair<ll, ll>> v;
for(int i = 0; i < n; i++){
ll a, b; cin>>a>>b;
v.push_back({(a+p-1)/p, b});
}
sort(all(v), [](const pair<ll, ll> &a, const pair<ll, ll> &b){
return a.first*b.second < b.first*a.second;
});
ll ans = 0;
ll time = 0;
for(auto&i : v){
time += i.first;
ans += (time-1)*i.second;
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int _t = 1;
// cin >> _t;
while (_t--) {
solve();
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1860 KiB | ||||
2 | Accepted | 3ms | 2220 KiB | ||||
subtask2 | 13/13 | ||||||
3 | Accepted | 3ms | 2368 KiB | ||||
4 | Accepted | 3ms | 2408 KiB | ||||
5 | Accepted | 3ms | 2532 KiB | ||||
6 | Accepted | 3ms | 2628 KiB | ||||
subtask3 | 22/22 | ||||||
7 | Accepted | 3ms | 3008 KiB | ||||
8 | Accepted | 3ms | 3088 KiB | ||||
9 | Accepted | 3ms | 3088 KiB | ||||
10 | Accepted | 2ms | 3156 KiB | ||||
11 | Accepted | 2ms | 3168 KiB | ||||
12 | Accepted | 3ms | 3244 KiB | ||||
13 | Accepted | 3ms | 3376 KiB | ||||
14 | Accepted | 3ms | 3592 KiB | ||||
subtask4 | 65/65 | ||||||
15 | Accepted | 37ms | 8684 KiB | ||||
16 | Accepted | 30ms | 9904 KiB | ||||
17 | Accepted | 32ms | 10848 KiB | ||||
18 | Accepted | 37ms | 12272 KiB | ||||
19 | Accepted | 37ms | 13552 KiB | ||||
20 | Accepted | 37ms | 14580 KiB | ||||
21 | Accepted | 37ms | 15888 KiB | ||||
22 | Accepted | 37ms | 16920 KiB | ||||
23 | Accepted | 34ms | 17976 KiB | ||||
24 | Accepted | 35ms | 19164 KiB |