Submission #1010919

#TimeUsernameProblemLanguageResultExecution timeMemory
1010919erraySki 2 (JOI24_ski2)C++17
0 / 100
1 ms600 KiB
// author: erray
#include <bits/stdc++.h>

#ifdef DEBUG
  #include "debug.h"
#else
  #define debug(...) void(37)
#endif

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> H(N), C(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i] >> C[i];
  }
  constexpr int64_t inf = int64_t(1e16);
  vector<int64_t> best(N, inf);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (i == j) continue;
      if (H[j] >= H[i]) {
        best[i] = min<int64_t>(best[i], C[j] + 1LL * (H[j] - H[i] + 1) * K);
      } else {
        best[i] = min<int64_t>(best[i], 0LL + C[j]);
      }
    }
  }
  debug(best);
  map<int, vector<int>> hs;
  for (int i = 0; i < N; ++i) {
    hs[H[i]].push_back(i);
  }
  hs[int(2e9)] = {};
  int last = -1;
  int64_t ans = 0;
  priority_queue<int64_t> pq;
  for (auto[pos, v] : hs) {
    while (last < pos && (!pq.empty() && pq.top() >= (1LL * last * K))) {
      ans += 1LL * last * K - pq.top();
      pq.pop();  
      ++last;
    }
    sort(v.begin(), v.end(), [&](int x, int y) {
      return C[x] < C[y];
    });
    for (int i = 1; i < int(v.size()); ++i) {
      int ind = v[i];
      ans += best[ind];
      pq.push(1LL * pos * K + best[ind]);
    }
    last = pos + 1;
  } 
  cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...