码迷,mamicode.com
首页 > 其他好文 > 详细

The Delivery Dilemma

时间:2020-11-06 01:18:03      阅读:19      评论:0      收藏:0      [点我收藏+]

标签:while   else   namespace   als   arch   ack   答案   lin   out   

链接 : 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

标签:while   else   namespace   als   arch   ack   答案   lin   out   

原文地址:https://www.cnblogs.com/phr2000/p/13929260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!