Submission

Status:

[PPPPP-SSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: meme_boi2

Problemset: จุดตัดบนกราฟ

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-20 11:27:10

#include <bits/stdc++.h>
using namespace std;
#define pii pair<double,double>
bool comp(pair<double,int> a, pair<double,int> b){
    if(a.first == b.first){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<double> pd(n);
    for(auto &x: pd) cin >> x;
    vector<pii> mat(n-1);
    mat[0] = {pd[0],pd[1]};
    
    vector<pair<double,int>> dp;
    if(mat[0].first > mat[0].second){
        swap(mat[0].first,mat[0].second);
    }
    dp.push_back({mat[0].first,1});
    dp.push_back({mat[0].second, - 1});
    for(int i = 1; i < n-1; i++){
        mat[i] = {pd[i] + 0.1,pd[i+1]};
        if(mat[i].first > mat[i].second){
            swap(mat[i].first,mat[i].second);
        }
        dp.push_back({mat[i].first,1});
        dp.push_back({mat[i].second,-1});
    }
    sort(dp.begin(),dp.end(),comp);
    int ans = 0, cur = 0;
    for(auto [x,y] : dp){
        cur += y;
        ans = max(ans,cur);
    }
    cout << ans;
}