結果
問題 |
No.2548 Problem Selection
|
ユーザー |
|
提出日時 | 2023-11-26 21:38:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 600 bytes |
コンパイル時間 | 2,067 ms |
コンパイル使用メモリ | 197,468 KB |
最終ジャッジ日時 | 2025-02-18 01:39:53 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> istream& operator >> (istream& is, vector<T>& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<ll> a(n), s(n); cin >> a; sort(a.begin(), a.end()); ll ans = 1ll << 61; for(int i = 0; i + 1 < n; i++){ s[i + 1] = s[i] + (a[i + 1] - a[i]) * (a[i + 1] - a[i]); } for(int i = 0; i + m - 1 < n; i++){ ans = min(ans, s[i + m - 1] - s[i]); } cout << ans << '\n'; }