結果
| 問題 | No.3459 Defeat Slimes |
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2026-02-28 14:09:54 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 418 ms / 3,000 ms |
| コード長 | 1,020 bytes |
| 記録 | |
| コンパイル時間 | 2,102 ms |
| コンパイル使用メモリ | 198,320 KB |
| 実行使用メモリ | 13,496 KB |
| 最終ジャッジ日時 | 2026-02-28 14:10:17 |
| 合計ジャッジ時間 | 15,491 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
int n;
long long y, z;
cin >> n >> y >> z;
vector<pair<long long, pair<long long, long long>>> lxc(n);
for (int i = 0; i < n; ++i)
{
long long c, l, x;
cin >> c >> l >> x;
lxc[i] = {l, {x, c}};
}
sort(lxc.begin(), lxc.end());
int nowid = 0;
long long ans = 0;
priority_queue<pair<long long, long long>> pq;
while (true)
{
while (nowid < n && lxc[nowid].first <= y)
{
pq.push(lxc[nowid].second);
++nowid;
}
long long ny = z;
if (nowid < n) ny = min(ny, lxc[nowid].first);
while (y < ny && !pq.empty())
{
long long nok = ny - y;
auto [x, c] = pq.top();
pq.pop();
long long cnt = min((nok + x - 1) / x, c);
y += cnt * x;
ans += cnt;
c -= cnt;
if (c > 0) pq.push({x, c});
}
if (y >= z) break;
if (y < ny)
{
ans = -1;
break;
}
}
cout << ans << endl;
}
テナガザル