結果

問題 No.2139 K Consecutive Sushi
ユーザー 👑 chro_96chro_96
提出日時 2022-12-03 00:30:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 8,140 KB
最終ジャッジ日時 2024-04-18 09:35:59
合計ジャッジ時間 2,499 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,972 KB
testcase_01 AC 3 ms
8,092 KB
testcase_02 AC 3 ms
8,028 KB
testcase_03 AC 76 ms
8,036 KB
testcase_04 AC 86 ms
8,092 KB
testcase_05 AC 74 ms
8,040 KB
testcase_06 AC 65 ms
8,096 KB
testcase_07 AC 72 ms
8,088 KB
testcase_08 AC 74 ms
7,920 KB
testcase_09 AC 80 ms
8,100 KB
testcase_10 AC 81 ms
8,068 KB
testcase_11 AC 82 ms
8,060 KB
testcase_12 AC 78 ms
8,060 KB
testcase_13 AC 4 ms
8,100 KB
testcase_14 AC 3 ms
8,040 KB
testcase_15 AC 3 ms
7,972 KB
testcase_16 AC 3 ms
8,100 KB
testcase_17 AC 4 ms
8,040 KB
testcase_18 AC 4 ms
8,128 KB
testcase_19 AC 4 ms
8,060 KB
testcase_20 AC 3 ms
7,960 KB
testcase_21 AC 3 ms
8,116 KB
testcase_22 AC 4 ms
8,040 KB
testcase_23 AC 9 ms
8,136 KB
testcase_24 AC 26 ms
8,032 KB
testcase_25 AC 58 ms
7,980 KB
testcase_26 AC 8 ms
8,112 KB
testcase_27 AC 23 ms
8,072 KB
testcase_28 AC 22 ms
8,092 KB
testcase_29 AC 12 ms
8,080 KB
testcase_30 AC 28 ms
8,032 KB
testcase_31 AC 73 ms
8,140 KB
testcase_32 AC 12 ms
8,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void set_segt (long long *t, int idx, long long val, int size) {
  idx = idx+size-1;
  t[idx] = val;
  
  while (idx > 0) {
    idx = (idx-1)/2;
    if (t[2*idx+1] < t[2*idx+2]) {
      t[idx] = t[2*idx+1];
    } else {
      t[idx] = t[2*idx+2];
    }
  }
  
  return;
}

long long min_segt_rec (long long *t, int a, int b, int k, int l, int r) {
  long long ans = 0LL;
  long long tmp = 0LL;
  
  if (r <= a || b <= l) {
    return 1000000000000000LL;
  }
  
  if (a <= l && r <= b) {
    return t[k];
  }
  
  ans = min_segt_rec(t, a, b, 2*k+1, l, (l+r)/2);
  tmp = min_segt_rec(t, a, b, 2*k+2, (l+r)/2, r);
  
  if (tmp < ans) {
    ans = tmp;
  }
  
  return ans;
}

long long min_segt (long long *t, int a, int b, int size) {
  return min_segt_rec(t, a, b, 0, 0, size);
}

int main () {
  int n = 0;
  int k = 0;
  long long a[200000] = {};
  
  int res = 0;
  
  long long sum = 0LL;
  long long segt[600000] = {};
  
  int size = 1;
  
  res = scanf("%d", &n);
  res = scanf("%d", &k);
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", a+i);
    sum += a[i];
  }
  
  while (size < n+1) {
    size *= 2;
  }
  
  for (int i = 0; i < n; i++) {
    long long val = min_segt(segt, i-k+1, i+1, size);
    set_segt(segt, i+1, val+a[i], size);
  }
  
  printf("%lld\n", sum-min_segt(segt, n-k+1, n+1, size));
  return 0;
}
0