結果
問題 |
No.2548 Problem Selection
|
ユーザー |
|
提出日時 | 2023-11-26 21:38:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 596 bytes |
コンパイル時間 | 1,986 ms |
コンパイル使用メモリ | 198,464 KB |
最終ジャッジ日時 | 2025-02-18 01:39:44 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 WA * 6 |
ソースコード
#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 < n; i++){ ans = min(ans, s[i + m - 1] - s[i]); } cout << ans << '\n'; }