QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202175 | #6632. Minimize Median | arseny_y# | RE | 0ms | 0kb | C++23 | 1.2kb | 2023-10-05 20:26:42 | 2023-10-05 20:26:42 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
for (auto &i : a) {
cin >> i;
}
sort(a.begin(), a.end());
vector<int> b(m + 1);
for (int i = 1; i <= m; ++i) {
cin >> b[i];
}
vector<int> dp(m + 1, LLONG_MAX);
dp[1] = b[1];
for (int i = 2; i <= m; ++i) {
dp[i] = min(dp[i], b[i]);
for (int j = i, cnt = 1; i * j <= m; j *= i, ++cnt) {
dp[i * j] = min(dp[i * j], dp[i] + b[i] * cnt);
}
}
int l = -1, r = a[n / 2] + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
auto na = a;
int cnt = 0;
int sm = 0;
for (int i = 0; cnt <= n / 2; ++i, ++cnt) {
if (a[i] <= mid) continue;
int x = max(2LL, a[i] / mid - 3);
while (a[i] / x > mid) {
++x;
}
sm += dp[x];
}
sm <= k ? r = mid : l = mid;
}
cout << r << '\n';
}
int32_t main(){
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
3 3 5 0 2 5 2 3 2 4 6 13 3 5 3 2 5 3 3 2 4 6 13 3 5 6 2 5 2 3 2 4 6 13