結果

問題 No.2408 Lakes and Fish
ユーザー tnakao0123tnakao0123
提出日時 2023-08-14 15:27:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 41,928 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 03:32:02
合計ジャッジ時間 2,551 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 50 ms
5,376 KB
testcase_05 AC 49 ms
5,376 KB
testcase_06 AC 50 ms
5,376 KB
testcase_07 AC 63 ms
5,376 KB
testcase_08 AC 62 ms
5,376 KB
testcase_09 AC 63 ms
5,376 KB
testcase_10 AC 62 ms
5,376 KB
testcase_11 AC 32 ms
5,376 KB
testcase_12 AC 45 ms
5,376 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 26 ms
5,376 KB
testcase_15 AC 50 ms
5,376 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 30 ms
5,376 KB
testcase_19 AC 47 ms
5,376 KB
testcase_20 AC 44 ms
5,376 KB
testcase_21 AC 49 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2408.cc:  No.2408 Lakes and Fish - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const int INF = 1 << 30;

/* typedef */

typedef long long ll;

/* global variables */

int ls[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", ls + i);

  ll sum = 0;
  while (m--) {
    int f, b, w;
    scanf("%d%d%d", &f, &b, &w);

    int k = lower_bound(ls, ls + n, f) - ls;
    int c0 = (k > 0) ? f - ls[k - 1] : INF;
    int c1 = (k < n) ? ls[k] - f : INF;
    int c = min(c0, c1);
    sum += max(b, w - c);
  }

  printf("%lld\n", sum);

  return 0;
}
0