結果

問題 No.2548 Problem Selection
ユーザー YwestbuilderkYwestbuilderk
提出日時 2024-01-22 20:00:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 514 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 80,716 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-22 20:00:33
合計ジャッジ時間 3,384 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
6,676 KB
testcase_01 AC 13 ms
6,676 KB
testcase_02 AC 48 ms
6,676 KB
testcase_03 AC 7 ms
6,676 KB
testcase_04 AC 30 ms
6,676 KB
testcase_05 AC 48 ms
6,676 KB
testcase_06 AC 8 ms
6,676 KB
testcase_07 AC 35 ms
6,676 KB
testcase_08 AC 40 ms
6,676 KB
testcase_09 AC 42 ms
6,676 KB
testcase_10 AC 50 ms
6,676 KB
testcase_11 AC 50 ms
6,676 KB
testcase_12 AC 50 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 RE -
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 3 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 RE -
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<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
#define int long long
signed main(){
	int N,M;
	cin >> N >> M;
	vector<int> a(N);
	for(int i = 0;i < N;i++) cin >> a[i];
	sort(a.begin(),a.end());
	vector<int> b(N - 1);
	for(int i = 0;i < N - 1;i++){
	b[i] = a[i + 1]  - a[i];
	b[i] = b[i] * b[i];
	
	}
	for(int i = 1;i < N - 1;i++)b[i] += b[i - 1];
	int ans = b[M - 2];
	for(int i = M - 1;i < N - 1;i++){
	ans = min(ans,b[i] - b[i - M + 1]);
	}
	cout << ans << endl;
}
0