64分求助
查看原帖
64分求助
373959
AFwhcing楼主2022/7/2 11:41

普及-啊……

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int n, l, r, maxs, maxe;
int a[1000010];
int maxtrue = 0, maxfalse = 0, sumt = 0, sumf = 0;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &l, &r);
		for (int j = l; j < r; ++j) {
			a[j] = 1;
		}
		maxs = min(maxs, l);
		maxe = max(maxe, r);
	}
	for (int i = maxs; i <= maxe; ++i) {
		if (a[i]) {
			sumt++;
			sumf = 0;
		} else {
			sumt = 0;
			if (i < maxe) {
				sumf++;
			}
		}
		maxtrue = max(maxtrue, sumt);
		maxfalse = max(maxfalse, sumf);
	}
	printf("%d %d", maxtrue, maxfalse);
	return 0;
}

2022/7/2 11:41
加载中...