0
点赞
收藏
分享

微信扫一扫

AcWing 1750. 救生员

深夜瞎琢磨 2022-02-05 阅读 49
c++

在这里插入图片描述

思路:暴力求区区最长覆盖

代码:

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
#define x first
#define y second
const int N = 110;
typedef pair<int, int> PII;
PII p[N];

int main()
{
 
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>p[i].x>>p[i].y;
    
    sort(p,p+n);
    
    int res=0;
    for(int i=0;i<n;i++){
        int sum=0,st=-1,ed=-1;
        for(int j=0;j<n;j++){
            if(j!=i){
                if(p[j].x<=ed) ed=max(ed,p[j].y);
                else{
                    sum+=ed-st;
                    st=p[j].x,ed=p[j].y;
                }
            }
            
        }
        sum+=ed-st;
        res=max(res,sum);
    }
    
    cout<<res<<endl;
 
    return 0;   
}
举报

相关推荐

0 条评论