P10189 [USACO24FEB] Maximizing Productivity B 的题解

一道比较简单的二分题。

我们只需要求出 Bessie 想要到达农场 i i i 最多能容忍的时间(即题目中的 S S S 减去 1 1 1 a i a_i ai,然后把它从小到大排序,在每次询问里面二分即可。

考场代码如下:

#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int, int> pr;
#define up(l, r, i) for(int i = (l); i <= (r); i++)
#define down(r, l, i) for(int i = (r); i >= (l); i--)
const int mod = 1000000007;
const int base = 2333;
const double eps = 1e-6;

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
	return x * f;
}

int n, m, k, Q, T, _, ans = 0;
int c[1000007];
int t[1000007];
int a[1000007];

signed main() {
	n = read(), Q = read();
	for(int i = 1; i <= n; i++) c[i] = read();
	for(int i = 1; i <= n; i++) t[i] = read(), a[i] = c[i] - t[i] - 1;
	sort(a + 1, a + n + 1);
//	for(int i = 1; i <= n; i++) cout << a[i] << " ";
//	cout << "\n";
	while(Q--) {
		int V = read(), S = read();
//		cout << "lower_bound:  " << (lower_bound(a + 1, a + n + 1, S) - a - 1) << "\n";
		int cnt = n - (lower_bound(a + 1, a + n + 1, S) - a - 1);
		if(cnt >= V) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值