結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー MM
提出日時 2026-02-28 14:54:34
言語 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
結果
WA  
実行時間 -
コード長 1,407 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,595 ms
コンパイル使用メモリ 391,352 KB
実行使用メモリ 20,120 KB
最終ジャッジ日時 2026-02-28 14:55:02
合計ジャッジ時間 23,175 ms
ジャッジサーバーID
(参考情報)
judge7 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec vector
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back 
#define eb emplace_back

using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
const ll mod = 998244353;
using mint = modint998244353;
const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
// using Graph = vector<vector<pair<int,ll>>>;
using Graph = vector<vector<int>>;

ll ceill(ll x, ll y){
  ll res = x / y;
  if(x % y > 0) res++;
  return res;
}

int main(){
  // input
  int N; ll Y,Z;
  cin >> N >> Y >> Z;
  vector<vector<ll>> P(N);
  rep(i,N){
    ll c,l,x;
    cin >> c >> l >> x;
    P[i] = {l,x,c};
  }
  sort(all(P));

  // solve
  int pos = 0;
  ll ans = 0, now = Y;
  priority_queue<pair<ll,ll>> pq;
  while(now < Z){
    if(pq.size()){
      auto[lev,num] = pq.top();
      pq.pop();
      ll tmp = ceill(Z-now,lev);
      if(tmp <= num){
        ans += tmp;
        now += tmp * lev;
        break;
      }
      else{
        ans += num;
        now += lev * num;
      }
    }

    while(pos < N && P[pos][0] <= now){
      pq.emplace(P[pos][1],P[pos][2]);
      pos++;
    }

    if(pq.empty()) break;
  }

  
  // output
  cout << (now >= Z ? ans : -1) << endl;
}
0