結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー Tehom
提出日時 2026-03-02 15:49:19
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 134 ms / 3,000 ms
コード長 1,425 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,869 ms
コンパイル使用メモリ 283,692 KB
実行使用メモリ 19,348 KB
最終ジャッジ日時 2026-03-02 15:49:33
合計ジャッジ時間 10,592 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repl(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

template <typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;}
template <typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;} return false;}


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

  int n; cin >> n;
  ll y,z; cin >> y >> z;
  using P=tuple<ll,ll,ll>;
  priority_queue<P,vector<P>,greater<P>> que;
  priority_queue<P> que2;
  rep(i,0,n){
    ll c,l,x; cin >> c >> l >> x;
    if(l<z) que.push({l,x,c});
  }
  ll ans=0;
  while(y<z){
    while(!que.empty()){
      auto [l,x,c]=que.top();
      if(l>y) break;
      que.pop();
      que2.push({x,l,c});
    }
    if(que2.empty()) break;
    auto [x,l,c]=que2.top();
    if(que.empty()){
      que2.pop();
      if(x>=(z-y)/c){
        ans+=(z-y-1)/x+1;
        y=z;
      }
      else{
        ans+=c;
        y+=x*c;
      }
    }
    else{
      auto [l2,x2,c2]=que.top();
      que2.pop();
      if(x<=(l2-y)/c){
        ans+=c;
        y+=x*c;
      }
      else{
        ans+=(l2-y-1)/x+1;
        que2.push({x,l,c-((l2-y-1)/1)});
        y+=x*((l2-y-1)/x+1);
      }
    }
  }
  if(y<z) cout << -1 << '\n';
  else cout << ans << '\n';
}
0