QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135627#6632. Minimize MedianOrange_JuiCEWA 1ms5900kbC++171.2kb2023-08-05 19:51:572023-08-05 19:51:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 19:51:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5900kb
  • [2023-08-05 19:51:57]
  • 提交

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: 5900kb

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'