QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749388 | #9123. Kth Sum | rtgsp | WA | 1ms | 9804kb | C++20 | 2.0kb | 2024-11-15 00:05:37 | 2024-11-15 00:05:38 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const int maxn = 1e7 + 2, mod = 1e9 + 7, inf = 1e9, LG = 20;
int n, k, a[maxn], b[maxn], c[maxn], ok, p, res;
ll bc[maxn], low, high, mid;
priority_queue<int> pq;
bool f (ll mid)
{
p = upper_bound(a + 1, a + n + 1, mid - bc[ok]) - a - 1;
if (1LL*p*ok >= mid) return true;
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, l = n; j <= n && l > 0; j++)
{
while (l > 0 && a[i] + b[j] + c[l] > mid) l--;
res += l;
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(1LL*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 ((int)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: 9784kb
input:
2 4 1 2 3 4 5 6
output:
10
result:
ok "10"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9744kb
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: -100
Wrong Answer
time: 1ms
memory: 9804kb
input:
1 1 1000000000 1000000000 1000000000
output:
-1294967296
result:
wrong answer 1st words differ - expected: '3000000000', found: '-1294967296'