結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー tau1235
提出日時 2026-02-28 16:04:48
言語 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  
実行時間 483 ms / 3,000 ms
コード長 647 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,054 ms
コンパイル使用メモリ 350,432 KB
実行使用メモリ 16,596 KB
最終ジャッジ日時 2026-02-28 16:05:07
合計ジャッジ時間 18,931 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int main(){
	using ll=long long;
	ll n,y,z;
	cin>>n>>y>>z;
	priority_queue<tuple<ll,ll,ll>> q;
	q.push({-z,0,0});
	for (int i=0;i<n;i++){
		ll c,l,x;
		cin>>c>>l>>x;
		q.push({-l,c,x});
	}
	priority_queue<pair<ll,ll>> q2;
	ll ans=0;
	while (y<z){
		while (-get<0>(q.top())<=y){
			auto [l,c,x]=q.top();
			q.pop();
			q2.push({x,c});
		}
		ll r=-get<0>(q.top())-y;
		while (!q2.empty()&&r>0){
			auto [x,c]=q2.top();
			q2.pop();
			ll q=min((r+x-1)/x,c);
			ans+=q;
			c-=q;
			y+=q*x;
			r-=q*x;
			if (c>0) q2.push({x,c});
		}
		if (r>0){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
}
0