結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー Carpenters-Cat
提出日時 2026-02-28 20:26:50
言語 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
結果
WA  
実行時間 -
コード長 935 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,466 ms
コンパイル使用メモリ 227,728 KB
実行使用メモリ 26,204 KB
最終ジャッジ日時 2026-02-28 20:27:08
合計ジャッジ時間 17,258 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using l1 = __int128_t;
int main () {
	int N;
	cin >> N;
	l1 Y, Z;
	{
		ll y, z;
		cin >> y >> z;
		Y = y;
		Z = z;
	}
	using T = tuple<l1, l1, l1>;
	std::vector<T> A(N);
	for (auto& [l, c, x] : A) {
		ll p, q, r;
		cin >> p >> q >> r;
		c = p; l = q; x = r;
	}
	sort(A.begin(), A.end(), greater<T>());
	priority_queue<T> pque;
	l1 ans = 0;
	for (int i = 0; i < N && Y < Z; i ++) {
		while (!A.empty()) {
			auto [l, c, x] = A.back();
			if (l <= Y) {
				A.pop_back();
				pque.emplace(x, c, l);
			} else {
				break;
			}
		}
		l1 nx = Z;
		if (!A.empty()) {
			nx = min(nx, get<0>(A.back()));
		}
		if (pque.empty()) continue;
		auto [x, c, l] = pque.top();
		pque.pop();
		l1 d = min(c, (nx - Y + x - 1) / x);
		Y += d * x;
		ans += d;
		c -= d;
		if (c > 0) pque.emplace(x, c, l);
	}
	if (Y >= Z) {
		cout << (ll)ans << endl;
	} else {
		cout << -1 << endl;
	}
}
0