求助 #7 WA
查看原帖
求助 #7 WA
324523
我叫课楼主2020/10/16 21:58

正确答案是912 184 我得到的是911 184 代码:

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

int n;
int l,r;
int start=1000000;
int end=0;
bool time_[1000006];
int length1,length2;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		if(l<start){
			start=l;
		}
		if(r>end){
			end=r;
		}
		for(int j=l;j<r;j++){
			time_[j]=1;
		}
	}
	int temp1=0,temp2=0;
	for(int i=start;i<end;i++){
		while(time_[i]==1){
			temp1++;
			i++;
		}
		if(temp1>length1){
			length1=temp1;
		}
		temp1=0;
		if(i==end){
			break;
		}
		while(time_[i]==0){
			temp2++;
			i++;
		}
		if(temp2>length2){
			length2=temp2;
		}
		temp2=0;
	}
	cout<<length1<<' '<<length2;
	return 0;
}
2020/10/16 21:58
加载中...