結果

問題 No.2548 Problem Selection
ユーザー cho435cho435
提出日時 2023-11-26 22:15:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 4,236 ms
コンパイル使用メモリ 265,612 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-26 22:15:25
合計ジャッジ時間 5,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 29 ms
6,676 KB
testcase_05 AC 49 ms
6,676 KB
testcase_06 AC 7 ms
6,676 KB
testcase_07 AC 36 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 49 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 1 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 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
	int n,m;
	cin>>n>>m;
	vector<ll> a(n);
	rep(i,n) cin>>a.at(i);
	sort(a.begin(),a.end());
	vector<ll> b(n-1);
	rep(i,n-1) b.at(i)=(a.at(i+1)-a.at(i))*(a.at(i+1)-a.at(i));
	vector<ll> c(n,0);
	rep(i,n-1) c.at(i+1)=c.at(i)+b.at(i);
	ll ans=1e18;
	rep(i,n-m+1){
		ans=min(ans,c.at(i+m-1)-c.at(i));
	}
	cout<<ans<<endl;
}
0