The Delivery Dilemma

链接 : http://codeforces.com/problemset/problem/1443/C

标签 : binary search greedy sorting *1400

二分答案

AC代码
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi firsqt
#define se second
#define inf 0x3f3f3f3f
const int N = 2e5 + 7;
ll a[N], b[N];
int n;
 
bool check(ll x) {
	ll sum = 0, ma = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] <= x) ma = max(ma, a[i]);
		else sum += b[i];
	}
	ma = max(ma, sum);
	return ma <= x;
}
 
int main() {	
	IO;
	int _;
	cin >> _;
	while (_--) {
		cin >> n;
		for (int i = 0; i < n; ++i) cin >> a[i];
		for (int i = 0; i < n; ++i) cin >> b[i];
		ll l = 1, r = 1e18;			
		while (l < r) {
			ll mid = l + r >> 1;
			if (check(mid)) r = mid;
			else l = mid + 1;
		}
		cout << l << endl;
	}
	return 0;
}

`

上一篇:redis 哨兵机制环境搭建


下一篇:题解 CF1443C 【The Delivery Dilemma】