QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485152#6632. Minimize Medianucup-team1525#WA 536ms126200kbC++202.0kb2024-07-20 14:13:362024-07-20 14:13:37

Judging History

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

  • [2024-07-20 14:13:37]
  • 评测
  • 测评结果:WA
  • 用时:536ms
  • 内存:126200kb
  • [2024-07-20 14:13:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int SIZ = 30000000 + 40;
const ll INF = 1e18;
char buf1[SIZ];
char *p1 = buf1, *p2 = buf1;
inline char readchar() {
    if (p1 == p2)
        p1 = buf1, p2 = buf1 + fread(buf1, 1, SIZ, stdin);
    return p1 == p2 ? EOF : *p1++;
}
int read() {
    int ret, c;
    while ((c = readchar()) > '9' || c < '0')
        ;
    ret = c - '0';
    while ((c = readchar()) >= '0' && c <= '9')
        ret = ret * 10 + c - '0';
    return ret;
}

const int N = 1e6 + 60;

int n, m;
ll K;
int a[N];
ll cost[N];
vector<int> div2[N];
ll dp[N];

void init() {
    for (int i = 1; i <= 1000000; i++) {
        for (int j = i; j <= 1000000; j += i)
            div2[j].push_back(i);
    }
}

void prep() {
    for (int i = 1; i <= m; i++)
        dp[i] = cost[i];
    for (int i = 1; i <= m; i++)
        for (auto &d : div2[i]) {
            dp[i] = min(dp[i], dp[d] + dp[i / d]);
        }
    for (int i = m - 1; i >= 1; i--)
        dp[i] = min(dp[i], dp[i + 1]);
}

bool check(int mid) {
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        cnt += (a[i] <= mid);
    if (cnt * 2 >= n) return true;
    ll total = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > mid) {
            int x = (a[i] + mid - 1) / mid;
            ll now = cost[x];
            if (now + total <= K)
                total += now, cnt++;
        }
        if (cnt * 2 >= n) return true;
    }
    return false;
}

void solve() {
    n = read(), m = read(), K = read();
    for (int i = 1; i <= n; i++)
        a[i] = read();
    for (int i = 1; i <= m; i++)
        cost[i] = read();
    prep();

    int l = 1, r = m, ans = m;
    while (l <= r) {
        int mid = l + (r - l) / 2;
        if (check(mid)) r = mid - 1, ans = mid;
        else l = mid + 1; 
    }
    cout << ans << '\n';
}

int main() {
    init();
    int T = read();
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 536ms
memory: 121944kb

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:

2
2
1

result:

ok 3 number(s): "2 2 1"

Test #2:

score: -100
Wrong Answer
time: 531ms
memory: 126200kb

input:

100000
5 10 5
3 7 1 10 10
11 6 11 6 1 8 9 1 3 1
5 6 51
2 2 2 5 1
42 61 26 59 100 54
5 10 76
7 5 8 4 7
97 4 44 83 61 45 24 88 44 44
5 8 90
1 1 5 1 3
35 15 53 97 71 83 26 7
5 3 52
1 1 3 1 1
22 6 93
5 6 28
6 6 1 3 1
9 31 2 19 10 27
5 8 31
3 6 2 1 2
32 29 13 7 57 34 9 5
5 6 75
3 3 4 5 4
40 56 38 60 17 3...

output:

7
2
3
1
1
1
2
3
3
4
3
4
2
2
3
1
1
4
2
1
3
1
1
2
2
1
2
3
3
5
6
1
3
6
2
2
2
1
1
3
6
1
1
1
3
4
1
1
2
1
2
2
1
8
6
4
1
1
5
1
1
5
1
4
1
4
3
7
1
1
6
4
1
1
1
1
2
1
1
4
7
4
4
8
3
2
1
1
2
1
4
3
2
4
4
1
5
1
4
1
1
2
2
1
2
2
1
1
2
1
1
1
1
1
4
2
2
4
3
2
4
1
2
1
2
4
2
6
3
3
2
6
7
2
4
1
3
1
1
1
2
1
7
1
1
2
3
2
2
5
...

result:

wrong answer 1st numbers differ - expected: '0', found: '7'