結果
問題 |
No.2548 Problem Selection
|
ユーザー |
|
提出日時 | 2024-10-28 01:32:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 739 bytes |
コンパイル時間 | 2,390 ms |
コンパイル使用メモリ | 199,028 KB |
最終ジャッジ日時 | 2025-02-25 01:00:11 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 WA * 3 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() const ll mod = 1e9 + 7; int main() { cin.tie(nullptr); int N, M; cin >> N >> M; vector<ll> A(N); rep(i, 0, N) cin >> A[i]; if (N == 1) { cout << 0 << '\n'; return 0; } sort(all(A)); vector<ll> S(N - 1); rep(i, 0, N - 1) S[i] = (A[i + 1] - A[i])*(A[i + 1] - A[i]); rep(i, 1, N - 1) S[i] += S[i - 1]; ll ans = LLONG_MAX; rep(i, 0, N - M + 1) { if (i == 0) ans = min(ans, S[i + M - 1]); else ans = min(ans, S[i + M - 2] - S[i - 1]); } cout << ans << '\n'; }