Submission

Status:

-P-P-P-P--

Subtask/Task Score:

40/100

Score: 40

User: dddrrrr

Problemset: ไฟส่อง

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-17 11:27:02

#include <bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0)->sync_with_stdio(0);
	
	int n;cin >> n;
	vector <pair <int ,int>> vec;
	for(int i=0 ;i<n ;i++){
		int x ,y;cin >> x >> y;
		if(x < y){
			vec.push_back({x ,1});
			vec.push_back({y ,-1});
		}
		else{
			//vec.push_back({x ,360});
			vec.push_back({x ,1});
			vec.push_back({360 ,-1});
			//vec.push_back({0 ,y});
			vec.push_back({0 ,1});
			vec.push_back({y ,-1});
		}
	}
	
	sort(vec.begin() ,vec.end());
	
	int mx = 0 ,start = INT_MAX , curr=0;
	for(int i=0 ;i<vec.size() ;i++){
		if(vec[i].second == 1){
			if(vec[i].first < start)start = vec[i].first;
			curr++;
		}
		else curr--;
		
		if(curr == 0){
			mx = max(mx ,vec[i].first - start);
			start = INT_MAX;
		}
		
	}
	cout << mx;
	
	

	return 0;
}