Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Jokul
Problemset: จุดตัดบนกราฟ
Language: cpp
Time: 0.025 second
Submitted On: 2026-03-15 10:27:07
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<long long> P(N);
for(int i = 0; i < N; i++) cin >> P[i];
vector<pair<long long,int>> ev;
for(int i = 0; i < N-1; i++){
long long l = min(P[i], P[i+1]);
long long r = max(P[i], P[i+1]);
ev.push_back({l, 1});
ev.push_back({r, -1});
}
sort(ev.begin(), ev.end(), [](auto &a, auto &b){
if(a.first == b.first) return a.second < b.second;
return a.first < b.first;
});
int cur = 0, ans = 0;
for(auto &e : ev){
cur += e.second;
ans = max(ans, cur);
}
cout << ans;
}