結果
問題 | No.2548 Problem Selection |
ユーザー |
|
提出日時 | 2023-11-18 01:00:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 751 bytes |
コンパイル時間 | 2,106 ms |
コンパイル使用メモリ | 198,876 KB |
最終ジャッジ日時 | 2025-02-17 22:25:37 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 60; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; assert(1 <= n && n <= 100000); assert(1 <= m && m <= 100000); assert(m <= n); vector<long long> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; assert(1LL <= a[i] && a[i] <= 1000000000LL); } sort(a.begin(), a.end()); vector<long long> s(n + 1); for(int i = 0; i < n; i++){ long long diff = (a[i + 1] - a[i]); diff *= diff; s[i + 1] = s[i] + diff; } long long ans = INF; for(int i = 0; i < n - m + 1; i++){ ans = min(ans, s[i + m - 1] - s[i]); } cout << ans << endl; }