結果
問題 |
No.3051 Make All Divisible
|
ユーザー |
|
提出日時 | 2025-01-18 16:05:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,158 bytes |
コンパイル時間 | 596 ms |
コンパイル使用メモリ | 80,336 KB |
実行使用メモリ | 13,772 KB |
最終ジャッジ日時 | 2025-02-08 15:03:42 |
合計ジャッジ時間 | 41,594 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 TLE * 13 |
ソースコード
// TLE #include <iostream> #include <limits> #include <numeric> #include <queue> #include <vector> void solve(int n, int k, std::vector<long long> a) { if (std::accumulate(a.begin(), a.end(), 0LL) % k != 0) { std::cout << -1 << '\n'; return; } std::priority_queue<long long> pq; const long long threshold = k * (k - 1) / 2; for (auto& e : a) pq.push(e); constexpr long long inf = std::numeric_limits<long long>::max(); long long ans = inf; long long t = std::accumulate(a.begin(), a.end(), 0LL) / k; for (;; --t) { long long e = pq.top(); if (e <= t) ans = t; pq.pop(); e -= k; if (e < 0) break; pq.push(e); } if (ans == inf) { std::cout << -1 << '\n'; } else { std::cout << ans << '\n'; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { int n, k; std::cin >> n >> k; std::vector<long long> a(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } solve(n, k, a); } }