QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749367#9123. Kth SumrtgspWA 8ms12144kbC++201.9kb2024-11-14 23:51:382024-11-14 23:51:39

Judging History

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

  • [2024-11-14 23:51:39]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:12144kb
  • [2024-11-14 23:51:38]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const int maxn = 1e6 + 2, mod = 1e9 + 7, inf = 1e9, LG = 20;
ll n, k, a[maxn], b[maxn], c[maxn], bc[maxn], ok, low, high, mid, p;
priority_queue<ll> pq;
bool f (ll mid)
{
    p = upper_bound(a + 1, a + n + 1, mid - bc[ok]) - a - 1;
    if (p*ok >= mid) return true;
    ll res = 0;
    for (int i = 1, j = n; i <= ok && j > p; i++)
    {
        while (j > p && bc[i] + a[j] > mid) j--;
        res += j - p;
        if (res >= k) return true;
    }
    for (int i = 1; i <= p; i++)
    {
        for (int j = 1, k = n; j <= n; j++)
        {
            while (k > 0 && a[i] + b[j] + c[k] > mid) k--;
            res += k;
            if (res >= k) return true;
        }
    }
    return false;
}
int main()
{
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    ok = sqrt(n*k);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) cin >> c[i];
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    sort(c + 1, c + n + 1);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            if ((ll)pq.size() < ok) pq.push(b[i] + c[j]);
            else
            {
                if (b[i] + c[j] < pq.top())
                {
                    pq.pop();
                    pq.push(b[i] + c[j]);
                }
                else break;
            }
        }
    ok = 0;
    while (!pq.empty())
    {
        bc[++ok] = pq.top();
        pq.pop();
    }
    reverse(bc + 1, bc + ok + 1);
    low = a[1] + b[1] + c[1]; high = a[n] + b[n] + c[n];
    while (low <= high)
    {
        mid = (low + high)/2;
        if (f(mid)) high = mid - 1;
        else low = mid + 1;
    }
    cout << low;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9840kb

input:

2 4
1 2
3 4
5 6

output:

10

result:

ok "10"

Test #2:

score: 0
Accepted
time: 1ms
memory: 9808kb

input:

10 40
11 9 13 12 15 11 11 2 11 17
3 1 10 2 12 18 9 11 11 15
14 9 4 14 16 9 20 2 1 18

output:

14

result:

ok "14"

Test #3:

score: 0
Accepted
time: 0ms
memory: 9668kb

input:

1 1
1000000000
1000000000
1000000000

output:

3000000000

result:

ok "3000000000"

Test #4:

score: -100
Wrong Answer
time: 8ms
memory: 12144kb

input:

314 12491830
429392519 92131736 9460149 448874040 5326166 804308891 571581523 580832602 110825817 11150177 47845585 886171410 888601860 633656718 879205016 333690452 739013504 118317331 8289119 502971381 486014573 167383690 96016893 556946780 634198668 389358242 984894049 735281439 58642904 22106451...

output:

1134303293

result:

wrong answer 1st words differ - expected: '1346801336', found: '1134303293'