結果

問題 No.2808 Concentration
ユーザー KudeKude
提出日時 2024-07-12 23:16:23
言語 C++23
(gcc 12.3.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
10,284 KB
testcase_01 AC 124 ms
10,920 KB
testcase_02 AC 97 ms
10,152 KB
testcase_03 AC 85 ms
10,156 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 42 ms
6,940 KB
testcase_08 AC 17 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 57 ms
8,664 KB
testcase_11 AC 56 ms
8,380 KB
testcase_12 AC 28 ms
6,944 KB
testcase_13 AC 86 ms
10,564 KB
testcase_14 AC 15 ms
6,944 KB
testcase_15 AC 78 ms
10,360 KB
testcase_16 AC 78 ms
10,136 KB
testcase_17 AC 99 ms
9,336 KB
testcase_18 AC 89 ms
12,380 KB
testcase_19 AC 45 ms
6,940 KB
testcase_20 AC 84 ms
11,292 KB
testcase_21 AC 76 ms
8,964 KB
testcase_22 AC 64 ms
8,312 KB
testcase_23 AC 49 ms
7,932 KB
testcase_24 AC 85 ms
9,840 KB
testcase_25 AC 45 ms
7,500 KB
testcase_26 AC 97 ms
9,196 KB
testcase_27 AC 105 ms
11,236 KB
testcase_28 AC 87 ms
13,336 KB
testcase_29 AC 88 ms
12,280 KB
testcase_30 AC 85 ms
12,464 KB
testcase_31 AC 89 ms
10,872 KB
testcase_32 AC 88 ms
12,808 KB
testcase_33 AC 86 ms
12,872 KB
testcase_34 AC 89 ms
10,768 KB
testcase_35 AC 95 ms
10,708 KB
testcase_36 AC 89 ms
11,844 KB
testcase_37 AC 104 ms
10,940 KB
testcase_38 AC 89 ms
10,636 KB
testcase_39 AC 97 ms
9,508 KB
testcase_40 AC 93 ms
10,180 KB
testcase_41 AC 88 ms
12,288 KB
testcase_42 AC 93 ms
11,768 KB
testcase_43 AC 93 ms
12,652 KB
testcase_44 AC 100 ms
9,640 KB
testcase_45 AC 93 ms
10,400 KB
testcase_46 AC 93 ms
9,992 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,944 KB
testcase_52 AC 2 ms
6,940 KB
testcase_53 AC 2 ms
6,940 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0