結果
| 問題 |
No.3051 Make All Divisible
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2025-03-08 00:21:50 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 193 ms / 2,000 ms |
| コード長 | 1,044 bytes |
| コンパイル時間 | 5,444 ms |
| コンパイル使用メモリ | 334,252 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 02:26:10 |
| 合計ジャッジ時間 | 7,061 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;
typedef long long ll;
void solve() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
{
ll sm = 0;
rep(i, 0, n) { sm += a[i]; }
if (sm % k != 0) {
cout << "-1\n";
return;
}
}
priority_queue<int> pq;
ll sm = 0;
rep(i, 0, n) {
a[i] = min(a[i], k * k + a[i] % k);
pq.push(a[i]);
sm += a[i];
}
ll ans = 1e9;
while (1) {
if ((ll)pq.top() <= sm / k) {
ans = min(ans, sm / k);
}
int tp = pq.top();
pq.pop();
if (tp < k)
break;
sm -= k;
pq.push(tp - k);
}
if (ans == 1e9)
ans = -1;
cout << ans << '\n';
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
SnowBeenDiding