QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135629 | #6632. Minimize Median | Orange_JuiCE | WA | 1ms | 5848kb | C++17 | 1.2kb | 2023-08-05 19:52:35 | 2023-08-05 19:52:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
const int N = 1e6 + 5;
int n, m, k, a[N], c[N];
bool check(int x) {
int cnt = 0;
for(int i = 1; i <= n; i++) if(a[i] > x) {
if(x == 0) cnt += c[a[i]+1];
else cnt += c[(a[i]-1)/x+1];
}
return cnt <= k;
}
void solve() {
cin >> n >> m >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a+1, a+1+n);
n = (n+1)/2;
for(int i = 1; i <= m; i++) cin >> c[i];
for(int i = m; i > 0; i--) c[i] = min(c[i], c[i+1]);
c[m+1] = c[1]+c[m];
for(int i = 1; i <= m+1; i++) {
for(int j = i; j <= m; j++) {
if(i*j > 2*m) break;
if(i*j > m) c[m+1] = min(c[i]+c[j], c[m+1]);
c[i*j] = min(c[i]+c[j], c[i*j]);
}
}
for(int i = m; i > 0; i--) c[i] = min(c[i], c[i+1]);
int l = 0, r = a[n], ans = a[(n+1)/2];
while(l<=r) {
int mid = (l+r)>>1;
if(check(mid)) r = mid-1, ans=mid;
else l = mid+1;
}
printf("%d\n", ans);
}
signed main() {
IOS;
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5848kb
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
output:
0 0 0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'