TLE * 2 求助!
查看原帖
TLE * 2 求助!
617314
TigerTanWQY楼主2024/9/22 00:02

#7 #10 TLE.

#include <iostream>
#include <algorithm>
using namespace std;
using LL = long long;

constexpr const int N = 1e5 + 3;
int a[N], b[N], n, m;

LL read() {
	LL res = 0;
	char ch = cin.get();
	for(; '0' > ch || ch > '9'; ch = cin.get());
	for(; '0' <= ch && ch <= '9'; ch = cin.get())
		res = res * 10 + ch - '0';
	return res;
}

LL check(const int tot) {
	LL res = 0;
	for(int i = 1; i <= n; ++i)
		res += upper_bound(b + 1, b + m + 1, tot - a[i]) - b - 1;
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	n = read(); m = read(); LL k = read();
	for(int i = 1; i <= n; ++i)
		a[i] = read();
	for(int i = 1; i <= m; ++i)
		b[i] = read();
	sort(a + 1, a + n + 1);
	sort(b + 1, b + m + 1);
	int L = 0, R = a[n] + b[m];
	while(L < R) {
		const int M = (L + R) >> 1;
		if(check(M) < k)
			L = M + 1;
		else
			R = M;
	}
	cout << L << endl;
	return 0;
}
2024/9/22 00:02
加载中...