fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int MOD1 = 1e9 + 7;
  5. using ll = long long;
  6. #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  7.  
  8. ll ceildiv(ll a, ll b){return 1LL * (a + b - 1) / b;}
  9.  
  10. ll n, x;
  11. const int N = 1e5 + 5;
  12. struct minion { ll a, h; };
  13. minion a[N];
  14.  
  15. void Input() {
  16. cin >> n >> x;
  17. for(int i = 0; i < n; i++)
  18. cin >> a[i].a >> a[i].h,
  19. a[i].h = ceildiv(a[i].h, x);
  20. }
  21.  
  22. void Solve() {
  23. sort(a, a + n, [&](minion a, minion b){ return a.a * b.h > a.h * b.a; });
  24. ll curr = 0;
  25. ll res = 0;
  26. for(int i = 0; i < n; i++) {
  27. curr += a[i].h;
  28. curr %= MOD1;
  29. res += curr * a[i].a;
  30. res %= MOD1;
  31. }
  32. cout << (res + 1) % MOD1 << "\n";
  33. }
  34.  
  35. int main()
  36. {
  37. optimize();
  38. Input();
  39. Solve();
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5448KB
stdin
Standard input is empty
stdout
1