Blue Bridge Cup Daily Question 2023.9.12

Lanqiao Cup 2022 Thirteenth Finals Real Questions-Cards-C Language Network (dotcpp.com)

Question description

On this day, Xiao Ming was sorting out his cards.

He has a total of n types of cards, the i-th card is printed with a positive integer number i (i ∈ [1, n]), and there are ai cards of the i-th type.

And if there are n cards, one of each type of card, then these n cards can be called a set of cards. In order to make up as many decks as possible, Xiao Ming took out m blank cards. He could write the number i on them and treat them as the i-th card to make up the deck. However, Xiao Ming felt that the handwritten cards were not very beautiful, so he decided to handwrite at most bi cards of the i-th type.

May I ask how many decks can Xiao Ming make at most?

analyze

The answer is monotonic! ! ! The answer is monotonic! ! ! The answer is monotonic! ! !

Two points two points two points! ! !

Note long long

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
ll n, m, a[N], b[N];
bool check(int mid)
{
	ll cnt = 0;
	for(int i = 1; i <= n ; i ++)
	{
		if(mid > a[i] + b[i])return false;
		if(a[i] < mid)cnt += mid - a[i];
	}
	if(cnt > m)return false;
	return true;
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++)
	{
		cin >> b[i];
	}
	ll l = 0, r = 0x3f3f3f;
	while(l + 1 != r)
	{
		int mid = (l + r) >> 1;
		if(check(mid))l = mid;
		else r = mid;
	}
	cout << l;
	return 0;
}

Supongo que te gusta

Origin blog.csdn.net/m0_75087931/article/details/132839857
Recomendado
Clasificación