結果
問題 | No.2548 Problem Selection |
ユーザー |
|
提出日時 | 2023-11-25 14:38:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 514 bytes |
コンパイル時間 | 1,655 ms |
コンパイル使用メモリ | 171,568 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-26 10:45:40 |
合計ジャッジ時間 | 2,820 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;#define REP(i,n) for(ll i=0;i<ll(n);i++)ll c[100010];int main(void){cin.tie(nullptr); ios_base::sync_with_stdio(false);ll i,j;ll N,M;cin >> N >> M;vector<ll> a(N);REP(i,N) cin >> a[i];sort(a.begin(),a.end());for(i=1;i<N;i++){c[i]=c[i-1]+(a[i]-a[i-1])*(a[i]-a[i-1]);}ll mn=1e18;for(i=0;i<N;i++){if(i+M-1<N){mn=min(mn,c[i+M-1]-c[i]);}}cout << mn << endl;return 0;}