結果

問題 No.716 距離
ユーザー megane_anko
提出日時 2021-03-23 01:54:55
言語 TypeScript
(5.7.2)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 8,427 ms
コンパイル使用メモリ 230,064 KB
実行使用メモリ 44,912 KB
最終ジャッジ日時 2024-12-31 16:35:22
合計ジャッジ時間 12,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import * as fs from 'fs';
const input = fs.readFileSync('/dev/stdin', 'utf8');

const nl_array = input.split('\n');
const N = parseInt(nl_array[0]);
const a_array = nl_array[1].split(' ');
const n_a_array = a_array.map(Number);

n_a_array.sort(
    function (a,b) {
        if (a < b) return -1;
        if (a > b) return 1;
        return 0;
    }
);

const diff = [];
for (let i = 0; i < N - 1; i++) {
    diff.push(n_a_array[i + 1] - n_a_array[i]);
}

diff.sort(
    function (a,b) {
        if (a < b) return -1;
        if (a > b) return 1;
        return 0;
    }
);

console.log(diff[0]);
console.log(n_a_array[N - 1] - n_a_array[0]);
0