結果

問題 No.2408 Lakes and Fish
ユーザー kinapharkinaphar
提出日時 2023-08-11 22:05:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,139 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 173,440 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-29 13:04:06
合計ジャッジ時間 6,534 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 237 ms
8,064 KB
testcase_05 AC 237 ms
8,064 KB
testcase_06 AC 204 ms
8,192 KB
testcase_07 AC 316 ms
8,192 KB
testcase_08 AC 312 ms
8,192 KB
testcase_09 AC 316 ms
8,192 KB
testcase_10 AC 320 ms
8,064 KB
testcase_11 AC 139 ms
5,376 KB
testcase_12 AC 222 ms
7,040 KB
testcase_13 AC 54 ms
5,376 KB
testcase_14 AC 111 ms
5,376 KB
testcase_15 AC 243 ms
6,528 KB
testcase_16 AC 84 ms
5,632 KB
testcase_17 AC 55 ms
5,376 KB
testcase_18 AC 145 ms
6,528 KB
testcase_19 AC 211 ms
5,888 KB
testcase_20 AC 160 ms
5,376 KB
testcase_21 AC 225 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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