結果

問題 No.2548 Problem Selection
ユーザー Today03Today03
提出日時 2023-11-25 17:59:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 207,160 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 17:59:40
合計ジャッジ時間 4,065 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
6,676 KB
testcase_01 AC 14 ms
6,676 KB
testcase_02 AC 47 ms
6,676 KB
testcase_03 AC 6 ms
6,676 KB
testcase_04 AC 30 ms
6,676 KB
testcase_05 AC 47 ms
6,676 KB
testcase_06 AC 7 ms
6,676 KB
testcase_07 AC 35 ms
6,676 KB
testcase_08 AC 39 ms
6,676 KB
testcase_09 AC 42 ms
6,676 KB
testcase_10 AC 49 ms
6,676 KB
testcase_11 AC 64 ms
6,676 KB
testcase_12 AC 49 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include("Today's/debug.cpp")
#include "Today's/debug.cpp"
#else
#define debug(...)
#define print_line
#define debugc(...)
#define cerr \
	if (false) cerr
#endif

int main() {
	int n, m;
	cin >> n >> m;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long ans = 0;
	for (int i = 0; i < m - 1; i++) {
		ans += (a[i + 1] - a[i]) * (a[i + 1] - a[i]);
	}
	long long tmp = ans;
	for (int i = 1; i + m - 1 < n; i++) {
		tmp -= (a[i] - a[i - 1]) * (a[i] - a[i - 1]);
		tmp += (a[i + m - 1] - a[i + m - 2]) * (a[i + m - 1] - a[i + m - 2]);
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}
0