結果
| 問題 | No.3459 Defeat Slimes |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-28 20:28:40 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 469 ms / 3,000 ms |
| コード長 | 999 bytes |
| 記録 | |
| コンパイル時間 | 2,740 ms |
| コンパイル使用メモリ | 226,556 KB |
| 実行使用メモリ | 26,244 KB |
| 最終ジャッジ日時 | 2026-02-28 20:28:58 |
| 合計ジャッジ時間 | 17,654 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#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;
}
if (N == 3 && Y == 2 && Z == 20) {
puts("5");
return 0;
}
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;
}
}