結果

問題 No.2601 Very Poor
ユーザー Maksym ShcherbanMaksym Shcherban
提出日時 2024-01-12 23:07:37
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 6,548 KB
実行使用メモリ 60,520 KB
最終ジャッジ日時 2024-03-20 19:50:00
合計ジャッジ時間 6,576 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
37,632 KB
testcase_01 AC 69 ms
37,632 KB
testcase_02 AC 71 ms
37,632 KB
testcase_03 AC 67 ms
37,632 KB
testcase_04 AC 68 ms
37,632 KB
testcase_05 AC 69 ms
37,760 KB
testcase_06 AC 70 ms
37,760 KB
testcase_07 AC 70 ms
37,760 KB
testcase_08 AC 70 ms
37,760 KB
testcase_09 AC 71 ms
37,760 KB
testcase_10 AC 69 ms
37,760 KB
testcase_11 AC 70 ms
37,760 KB
testcase_12 AC 69 ms
37,760 KB
testcase_13 AC 69 ms
37,760 KB
testcase_14 AC 71 ms
37,760 KB
testcase_15 AC 262 ms
60,392 KB
testcase_16 AC 186 ms
60,520 KB
testcase_17 AC 189 ms
60,520 KB
testcase_18 AC 186 ms
60,520 KB
testcase_19 AC 186 ms
60,520 KB
testcase_20 AC 188 ms
60,520 KB
testcase_21 AC 188 ms
60,520 KB
testcase_22 AC 186 ms
60,520 KB
testcase_23 AC 186 ms
60,520 KB
testcase_24 AC 189 ms
60,520 KB
testcase_25 AC 188 ms
60,520 KB
testcase_26 AC 187 ms
60,520 KB
testcase_27 AC 188 ms
60,520 KB
testcase_28 AC 188 ms
60,520 KB
testcase_29 AC 187 ms
60,520 KB
testcase_30 AC 188 ms
60,520 KB
testcase_31 AC 188 ms
60,520 KB
testcase_32 AC 188 ms
60,520 KB
testcase_33 AC 189 ms
60,520 KB
testcase_34 AC 191 ms
60,520 KB
testcase_35 AC 69 ms
37,760 KB
testcase_36 AC 71 ms
37,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input) {
  const lines = input.split('\n').map(x => x.trim()).filter(Boolean);
  const [n, x] = lines[0].split(' ').map(Number);
  const a = lines[1].split(' ').map(Number);

  let head = 0;
  let tail = 0;
  let length = 0;
  let best = 0;
  let current = 0;
  let tailMoved = false;
  while (true) {
    if (head === tail) {
      current += a[head];
      head = (head + 1) % a.length;
      length++;
    } else {
      if (current > x) {
        current -= a[tail];
        tail = (tail + 1) % a.length;
        tailMoved = true;
        length--;
      } else {
        current += a[head];
        head = (head + 1) % a.length;
        length++;
      }
    }
    if (tailMoved && tail === 0 || length > a.length) {
      break;
    }
    if (current <= x) {
      best = Math.max(best, current);
    }
  }
  console.log(best);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0