The Delivery Dilemma

Posted phr2000

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

`

以上是关于The Delivery Dilemma的主要内容,如果未能解决你的问题,请参考以下文章

论文笔记The Dilemma between Deduplication and Locality: Can Both be Achieved?

论文笔记The Dilemma between Deduplication and Locality: Can Both be Achieved?

(Incomplete)UVa 701 The Archeologist's Dilemma

环境初始化 Build and Install the Apache Thrift IDL Compiler Install the Platform Development Tools(代码片段

maven web项目的web.xml报错The markup in the document following the root element must be well-formed.(代码片段

What's the difference between @Component, @Repository & @Service annotations in Spring?(代码片段