結果
問題 |
No.2548 Problem Selection
|
ユーザー |
![]() |
提出日時 | 2023-11-25 17:59:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 696 bytes |
コンパイル時間 | 3,630 ms |
コンパイル使用メモリ | 198,500 KB |
最終ジャッジ日時 | 2025-02-18 01:03:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; #if __has_include("Today's/debug.cpp") #include "Today's/debug.cpp" #else #define debug(...) #define print_line #define debugc(...) #define cerr \ if (false) cerr #endif int main() { 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()); long long ans = 0; for (int i = 0; i < m - 1; i++) { ans += (a[i + 1] - a[i]) * (a[i + 1] - a[i]); } long long tmp = ans; for (int i = 1; i + m - 1 < n; i++) { tmp -= (a[i] - a[i - 1]) * (a[i] - a[i - 1]); tmp += (a[i + m - 1] - a[i + m - 2]) * (a[i + m - 1] - a[i + m - 2]); ans = min(ans, tmp); } cout << ans << endl; }