QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#587663#6632. Minimize MedianKandarp08WA 60ms3592kbC++202.7kb2024-09-24 21:00:222024-09-24 21:00:23

Judging History

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

  • [2024-09-24 21:00:23]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:3592kb
  • [2024-09-24 21:00:22]
  • 提交

answer

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define MOD 1000000007
#define HASH_MOD1 998244353
#define HASH_MOD2 1000000009
#define HASH 31
#define ll long long
#define int long long

typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

template <typename T>
istream& operator>> (istream& in, vector<T>& a)
{
    for (int i = 0; i < a.size(); ++i)
        in >> a[i];

    return in;
}

template <typename T>
ostream& operator<< (ostream& out, vector<T>& a)
{
    for (int i = 0; i < a.size(); ++i)
        out << a[i] << " ";

    out << "\n";

    return out;
}

template <typename T>
ostream& operator<< (ostream& out, set<T>& s)
{
    for (int x : s)
        out << x << " ";

    out << "\n";

    return out;
}

template <typename T>
ostream& operator<< (ostream& out, vector<pair<T, T>>& v)
{
    for (int i = 0; i < v.size(); ++i)
        out << v[i].first << " " << v[i].second << "\n";

    return out;
}

ll modinv(ll a)
{
    return a <= 1 ? a : MOD - (MOD / a) * modinv(MOD % a) % MOD; 
}

ll binpow(ll x, ll y)
{
    ll ans = 1;

    while (y > 0)
    {
        if (y % 2 == 1)
            ans *= x;

        x = x * x;
        y = y / 2;

        x %= MOD;
        ans %= MOD;
    }

    return ans;
}

void solve()
{
    int n, m, k, i;
    cin >> n >> m >> k;

    vector<int> a(n), cost(m + 1);
    cin >> a;

    for (i = 1; i <= m; ++i)
        cin >> cost[i];

    for (i = m - 1; i >= 1; --i)
        cost[i] = min(cost[i], cost[i + 1]);

    vector<int> min_cost = cost;

    for (i = 1; i <= m; ++i)
    {
        for (int j = 2 * i; j <= m; j += i)
            min_cost[j] = min(min_cost[j], min_cost[i] + min_cost[j / i]);
    }    

    for (i = m - 1; i >= 1; --i)
        min_cost[i] = min(min_cost[i], min_cost[i + 1]);

    sort(a.begin(), a.end());

    int ans = a[n - 1];
    int low = 0;
    int high = a[n - 1];

    while (low <= high)
    {
        int mid = (low + high) / 2;
        int total = 0;

        for (i = 0; i < n / 2 + n % 2; ++i)
        {
            if (a[i] > mid)
                total += min_cost[(a[i] + mid + 1) / (mid + 1)];
        }

        if (total <= k)
        {
            ans = mid;
            high = mid - 1;
        }

        else
            low = mid + 1;
    }

    cout << ans << "\n";
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;

    while (t--)
    {
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

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: 60ms
memory: 3592kb

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:

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

result:

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