結果
| 問題 | No.2408 Lakes and Fish | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-08-11 22:05:43 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 286 ms / 2,000 ms | 
| コード長 | 1,139 bytes | 
| コンパイル時間 | 1,829 ms | 
| コンパイル使用メモリ | 173,636 KB | 
| 実行使用メモリ | 8,320 KB | 
| 最終ジャッジ日時 | 2024-11-18 16:27:52 | 
| 合計ジャッジ時間 | 6,389 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define I_MAX 2147483647;
#define LL_MAX 9223372036854775806;
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
int main() {
  ll n, m, l, f, b, w, x;
  ll ans = 0;
  set<ll> st;
  cin >> n >> m;
  rep(i, n) {
    cin >> l;
    st.insert(l);
    st.insert(-1);
    st.insert(1000000001);
  }
  rep(i, m) {
    cin >> f >> b >> w;
    if (st.count(f) == 1) {
      ans += w;
    } else {
      x = b;
      st.insert(f);
      auto itr = st.find(f);
      itr--;
      // cout << "マイナス方向を見る: " << *itr << endl;
      if (*itr != -1) {
        x = max(x, w - (f - *itr));
      }
      itr++;
      itr++;
      // cout << "プラス方向を見る: " << *itr << endl;
      if (*itr != 1000000001) {
        x = max(x, w - (*itr - f));
      }
      st.erase(f);
      ans += x;
    }
  }
  cout << ans;
}
            
            
            
        