結果

問題 No.2548 Problem Selection
ユーザー HIKKY1317HIKKY1317
提出日時 2023-11-25 13:53:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 486 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 172,516 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 13:53:18
合計ジャッジ時間 3,558 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
6,676 KB
testcase_01 AC 14 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 48 ms
6,676 KB
testcase_06 AC 7 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 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 1 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;

int main(){
  int N,M;
  cin >> N >> M;
  long long A[N+1];
  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  sort(A+1,A+N+1);
  vector<long long> vec;
  for(int i=2;i<=N;i++){
    vec.push_back((A[i]-A[i-1])*(A[i]-A[i-1]));
  }
  long long ans=0;
  for(int i=0;i<M-1;i++){
    ans+=vec[i];
  }
  long long num=ans;
  for(int i=M-1;i<vec.size();i++){
    num-=vec[i-(M-1)];
    num+=vec[i];
    ans=min(ans,num);
  }
  cout << ans << endl;
}
0