【洛谷】P10417 [蓝桥杯 2023 国 A] 第 K 小的和 的题解
题解
CSP-S1 补全程序,致敬全 A 的答案,和神奇的预言家。
写一下这篇的题解说不定能加 CSP 2024 的 RP
代码
#include <bits/stdc++.h>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int long long
namespace fastIO {
inline int read() {
register int x = 0, f = 1;
register char c = getchar();
while (c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
}
using namespace fastIO;
int n, m, k, a[100005], b[100005];
bool check (int x) {
int res = 0;
for (int i = 1; i <= n; i++) {
res += upper_bound (b + 1, b + m + 1, x - a[i]) - b - 1;
}
return res >= k;
}
signed main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n = read(), m = read(), k = read();
for(int i = 1; i <= n; i ++) {
a[i] = read();
}
for(int i = 1; i <= m; i ++) {
b[i] = read();
}
sort(b + 1, b + m + 1);
int l = 0, r = INT_MAX;
while (l < r) {
int mid = (l + r) >> 1;
if (check (mid)) {
r = mid;
}
else l = mid + 1;
}
write(l);
return 0;
}
标签:int,题解,namespace,mid,long,蓝桥,read,P10417
From: https://blog.csdn.net/ZH_qaq/article/details/142439049