結果

問題 No.2408 Lakes and Fish
ユーザー 👑 chro_96chro_96
提出日時 2023-08-11 21:38:27
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 29,568 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 12:29:40
合計ジャッジ時間 2,180 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 58 ms
5,376 KB
testcase_05 AC 59 ms
5,376 KB
testcase_06 AC 57 ms
5,376 KB
testcase_07 AC 62 ms
5,376 KB
testcase_08 AC 62 ms
5,376 KB
testcase_09 AC 64 ms
5,376 KB
testcase_10 AC 63 ms
5,376 KB
testcase_11 AC 34 ms
5,376 KB
testcase_12 AC 45 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 26 ms
5,376 KB
testcase_15 AC 52 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 14 ms
5,376 KB
testcase_18 AC 30 ms
5,376 KB
testcase_19 AC 49 ms
5,376 KB
testcase_20 AC 46 ms
5,376 KB
testcase_21 AC 51 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  int l[100000] = {};
  int f = 0;
  long long b = 0LL;
  long long w = 0LL;
  
  int res = 0;
  
  long long ans = 0LL;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", l+i);
  }
  for (int i = 0; i < m; i++) {
    res = scanf("%d", &f);
    res = scanf("%lld", &b);
    res = scanf("%lld", &w);
    ans += b;
    if (f <= l[0] && w-((long long)(l[0]-f)) > b) {
      ans += w-((long long)(l[0]-f))-b;
    } else if (f >= l[n-1] && w-((long long)(f-l[n-1])) > b) {
      ans += w-((long long)(f-l[n-1]))-b;
    } else if (f > l[0] && f < l[n-1]) {
      int idx[2] = { 0, n-1 };
      while (idx[1]-idx[0] > 1) {
        int nxt = (idx[0]+idx[1])/2;
        if (l[nxt] < f) {
          idx[0] = nxt;
        } else {
          idx[1] = nxt;
        }
      }
      if (f-l[idx[0]] < l[idx[1]]-f && w-((long long)(f-l[idx[0]])) > b) {
        ans += w-((long long)(f-l[idx[0]]))-b;
      } else if (w-((long long)(l[idx[1]]-f)) > b) {
        ans += w-((long long)(l[idx[1]]-f))-b;
      }
    }
  }
  
  printf("%lld\n", ans);
  return 0;
}
0