T3 WA 74pts

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t, n, m;
struct node {
	int l, r;
} a[100005];
bool check(int mid) {
	int maxx = 0, ans = 0;
	for (int i = 1; i <= m; i++) {
		maxx = max(maxx, a[i].l);
		if (a[i].r >= maxx) {
			ans += (a[i].r - maxx) / mid + 1;
			maxx += ((a[i].r - maxx) / mid + 1) * mid;
		}
	}
	if (ans >= n) return 1;
	return 0;
}
signed main() {
	cin >> t;
	while (t--) {
		int ans = 0;
		cin >> n >> m;
		for (int i = 1; i <= m; i++) {
			cin >> a[i].l >> a[i].r;
			if (a[i].l > a[i].r) swap(a[i].l, a[i].r);
			ans += a[i].r - a[i].l + 1;
		}
		if (ans < n) {
			cout << 0 << "\n";
			continue;
		}
		sort(a + 1, a + m + 1, [&] (node x, node y) {
			return x.l < y.l;
		});
		int l = 1, r = 1e18;
		while (l < r) {
			int mid = (l + r + 1) / 2;
			if (check(mid)) l = mid;
			else r = mid - 1;
		}
		cout << l << "\n";
	}
	return 0;
}

image

稍等,我看看

好像漏了一种条件,只有一个人的时候,输出最右边作为的编号

改了就过了

谢谢老师

1 个赞

不客气 :rose:

是加一段

		if (n == 1) {
			cout << a[m].r;
			continue;
		}

吗?为什么我还是过不了,老师能帮忙看一下吗

放在sort后面

我放在 sort 后面了

哦,你没换行

已通过,谢谢老师!

1 个赞

%%%orz