97522024-03-06 12:57:42FulopMateSzörnyekcpp17Accepted 100/10037ms19164 KiB
#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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1860 KiB
2Accepted3ms2220 KiB
subtask213/13
3Accepted3ms2368 KiB
4Accepted3ms2408 KiB
5Accepted3ms2532 KiB
6Accepted3ms2628 KiB
subtask322/22
7Accepted3ms3008 KiB
8Accepted3ms3088 KiB
9Accepted3ms3088 KiB
10Accepted2ms3156 KiB
11Accepted2ms3168 KiB
12Accepted3ms3244 KiB
13Accepted3ms3376 KiB
14Accepted3ms3592 KiB
subtask465/65
15Accepted37ms8684 KiB
16Accepted30ms9904 KiB
17Accepted32ms10848 KiB
18Accepted37ms12272 KiB
19Accepted37ms13552 KiB
20Accepted37ms14580 KiB
21Accepted37ms15888 KiB
22Accepted37ms16920 KiB
23Accepted34ms17976 KiB
24Accepted35ms19164 KiB