結果

問題 No.2408 Lakes and Fish
ユーザー yansi819yansi819
提出日時 2024-04-07 13:16:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 4,541 ms
コンパイル使用メモリ 262,820 KB
実行使用メモリ 6,728 KB
最終ジャッジ日時 2024-04-07 13:16:37
合計ジャッジ時間 8,693 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 155 ms
6,728 KB
testcase_05 AC 154 ms
6,728 KB
testcase_06 AC 147 ms
6,728 KB
testcase_07 AC 172 ms
6,728 KB
testcase_08 AC 173 ms
6,728 KB
testcase_09 AC 172 ms
6,728 KB
testcase_10 AC 172 ms
6,728 KB
testcase_11 AC 90 ms
6,548 KB
testcase_12 AC 123 ms
6,548 KB
testcase_13 AC 34 ms
6,548 KB
testcase_14 AC 71 ms
6,548 KB
testcase_15 AC 139 ms
6,548 KB
testcase_16 AC 49 ms
6,548 KB
testcase_17 AC 39 ms
6,548 KB
testcase_18 AC 83 ms
6,548 KB
testcase_19 AC 131 ms
6,548 KB
testcase_20 AC 128 ms
6,548 KB
testcase_21 AC 136 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int N, M;
ll L[101010], F[101010], B[101010], W[101010];

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> L[i];
  for (int i = 0; i < M; i++) cin >> F[i] >> B[i] >> W[i];
  ll ans = 0;
  for (int i = 0; i < M; i++) {
    int pos1 = lower_bound(L, L + N, F[i]) - L;
    if (pos1 == 0) {
      if (abs(L[pos1] - F[i]) < W[i] - B[i]) ans += W[i] - abs(L[pos1] - F[i]);
      else ans += B[i];
    } else if (pos1 == N) {
      if (abs(L[pos1 - 1] - F[i]) < W[i] - B[i]) ans += W[i] - abs(L[pos1 - 1] - F[i]);
      else ans += B[i];
    } else {
      if (min(abs(L[pos1] - F[i]), abs(L[pos1 - 1] - F[i])) < W[i] - B[i]) ans += W[i] - min(abs(L[pos1] - F[i]), abs(L[pos1 - 1] - F[i]));
      else ans += B[i];
    }
  }
  cout << ans << endl;
  return 0;
}
0