Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: .n0t_gloomy.
Problemset: จุดตัดบนกราฟ
Language: cpp
Time: 0.058 second
Submitted On: 2026-04-04 20:46:57
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n;
cin>>n;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
vector<int> v(n);
for (int i = 0; i < n; i++) cin>>v[i];
for (int i = 1; i < n; i++)
{
int a = v[i-1], b = v[i];
if (a < b)
{
pq.push({a,1});
pq.push({b,-1});
}
else
{
pq.push({b,1});
pq.push({a,-1});
}
}
int cur = 0, mx = 0;
while (!pq.empty())
{
auto [val,delta] = pq.top();
pq.pop();
cur += delta;
mx = max(mx,cur);
}
cout<<mx<<"\n";
}