結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー takumi152
提出日時 2026-02-28 14:39:40
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 218 ms / 3,000 ms
コード長 1,898 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,444 ms
コンパイル使用メモリ 211,664 KB
実行使用メモリ 20,556 KB
最終ジャッジ日時 2026-02-28 14:39:53
合計ジャッジ時間 9,766 ms
ジャッジサーバーID
(参考情報)
judge5 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, y, z;
  cin >> n >> y >> z;
  vector<ll> c(n), l(n), x(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> l[i] >> x[i];
  }

  priority_queue<pair<ll, ll>> defeat_que;
  priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>> locked_que;
  for (int i = 0; i < n; i++) {
    if (y >= l[i]) {
      defeat_que.emplace(x[i], c[i]);
    }
    else {
      locked_que.emplace(l[i], x[i], c[i]);
    }
  }

  ll ans = 0;
  ll current_level = y;
  while (!defeat_que.empty()) {
    auto next_defeat = defeat_que.top();
    defeat_que.pop();

    ll target_level;
    if (!locked_que.empty()) {
      auto next_locked = locked_que.top();
      target_level = min(z, get<0>(next_locked));
    }
    else {
      target_level = z;
    }

    auto defeat_count = min(next_defeat.second, (target_level - current_level + next_defeat.first - 1) / next_defeat.first);

    ans += defeat_count;
    current_level += next_defeat.first * defeat_count;

    if (defeat_count < next_defeat.second) {
      defeat_que.emplace(next_defeat.first, next_defeat.second - defeat_count);
    }

    while (!locked_que.empty()) {
      auto next_unlock = locked_que.top();
      if (current_level >= get<0>(next_unlock)) {
        defeat_que.emplace(get<1>(next_unlock), get<2>(next_unlock));
        locked_que.pop();
      }
      else {
        break;
      }
    }

    if (current_level >= z) break;
  }

  if (current_level >= z) {
    cout << ans << endl;
  }
  else {
    cout << -1 << endl;
  }

  return 0;
}
0