結果

問題 No.2548 Problem Selection
ユーザー daiota
提出日時 2023-11-25 13:49:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 544 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 171,660 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-26 10:33:06
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)



int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	int i,j;

	int N,M;
	cin >> N >> M;
	vector<ll> a(N);
	REP(i,N) cin >> a[i];

	sort(a.begin(),a.end());

	int p=-1;
	ll mn=1e18;;
	for(i=0;i<N;i++){
		if(i+M-1<N && mn>a[i+M-1]-a[i]){
			mn=a[i+M-1]-a[i];
			p=i;
		}
	}


	ll S=0;
	for(i=p+1;i<=p+M-1;i++){
		S+=(a[i]-a[i-1])*(a[i]-a[i-1]);
	}


	cout << S << endl;



	return 0;
}
0