結果
| 問題 |
No.2808 Concentration
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2024-07-12 23:16:23 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 2,000 ms |
| コード長 | 2,159 bytes |
| コンパイル時間 | 4,135 ms |
| コンパイル使用メモリ | 280,260 KB |
| 実行使用メモリ | 13,336 KB |
| 最終ジャッジ日時 | 2024-07-12 23:17:26 |
| 合計ジャッジ時間 | 11,220 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
template <class T, class Comp = less<T>>
struct erasable_priority_queue {
priority_queue<T, vector<T>, Comp> q, q_erase;
void push(T x) { q.push(move(x)); }
template <class... Args>
void emplace(Args&&... args) {
q.emplace(forward<Args>(args)...);
}
void erase(T x) { q_erase.push(move(x)); }
decltype(auto) top() {
assert(!empty());
expose_top();
return q.top();
}
void pop() {
assert(!empty());
expose_top();
q.pop();
}
int size() { return int(q.size()) - int(q_erase.size()); }
bool empty() { return !size(); }
void expose_top() {
while (!q_erase.empty() && q_erase.top() == q.top()) {
q_erase.pop();
q.pop();
}
}
};
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, s, h;
cin >> n >> s >> h;
struct S {
int x, y, z;
};
vector<S> d(n);
for (auto& [x, y, z] : d) cin >> x >> y >> z;
VL z_acc(n + 1);
rep(i, n) z_acc[i+1] = z_acc[i] + d[i].z;
constexpr int INF = 1001001001;
d.emplace_back(2 * INF, 2 * INF, 0);
VL dp(n + 1);
int ptr1 = 0, ptr2 = 0;
erasable_priority_queue<ll> q;
rep(i, n) {
chmax(dp[i+1], dp[i]);
q.emplace(dp[i] - z_acc[i]);
while (d[i].y - d[ptr1].x > s) {
q.erase(dp[ptr1] - z_acc[ptr1]);
ptr1++;
}
if (!q.empty()) {
while (d[ptr2].x - d[i].y < h) ptr2++;
chmax(dp[ptr2], q.top() + z_acc[i+1]);
}
}
cout << dp[n] << '\n';
}
Kude