結果
問題 |
No.2548 Problem Selection
|
ユーザー |
![]() |
提出日時 | 2023-11-25 22:09:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 760 bytes |
コンパイル時間 | 468 ms |
コンパイル使用メモリ | 44,800 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-26 11:21:51 |
合計ジャッジ時間 | 1,421 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
/* -*- coding: utf-8 -*- * * 2548.cc: No.2548 Problem Selection - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 100000; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N]; ll dds[MAX_N], ddss[MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); sort(as, as + n); for (int i = 0; i + 1 < n; i++) { int d = as[i + 1] - as[i]; dds[i] = (ll)d * d; ddss[i + 1] = ddss[i] + dds[i]; } ll mins = LINF; for (int i = 0; i + m - 1 < n; i++) mins = min(mins, ddss[i + m - 1] - ddss[i]); printf("%lld\n", mins); return 0; }