其他分享
首页 > 其他分享> > The Delivery Dilemma

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;
}

`

标签:Dilemma,int,ll,mid,cin,Delivery,++,define
来源: https://www.cnblogs.com/phr2000/p/13929260.html