Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Test

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

Language: cpp

Time: 0.032 second

Submitted On: 2025-12-30 21:49:57

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int prev;
    cin >> prev;
    vector<pair<int,int>> event;
    for(int i=1;i<n;i++){
        int y;
        cin >> y;

        int mn = min(prev,y);
        int mx = max(prev,y);

        event.push_back({mn, +1});
        event.push_back({mx, -1});

        prev = y;
    }

    sort(event.begin(), event.end());

    int sum=0,ans=0;
    for(auto &x : event){
        sum += x.second;
        ans = max(ans, sum);
    }
    cout << ans;
}