結果
問題 |
No.2548 Problem Selection
|
ユーザー |
![]() |
提出日時 | 2023-11-29 04:24:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 593 bytes |
コンパイル時間 | 2,001 ms |
コンパイル使用メモリ | 199,260 KB |
最終ジャッジ日時 | 2025-02-18 02:20:30 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n, m; cin >> n >> m; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); vector<long long> cum(n); for (int i = 1; i < n; i++) { cum[i] = cum[i - 1] + (a[i] - a[i - 1]) * (a[i] - a[i - 1]); } long long ans = 9e18; for (int i = 0; i <= n - m; i++) { ans = min(ans, cum[i + m - 1] - cum[i]); } cout << ans << endl; }