Submission
Status:
[PPPPPPPPP-SSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: kenmuay
Problemset: จุดตัดบนกราฟ
Language: cpp
Time: 0.032 second
Submitted On: 2026-02-28 22:36:19
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
struct GRAPH {
int u,w;
bool operator < (const GRAPH &o) const{
if(u != o.u) return u<o.u;
return w<o.w;
}
};
vector<GRAPH> v;
int main() {
cin.tie(nullptr)->sync_with_stdio(0);
int n;
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i];
}
for(int i=1; i<n; i++){
if(a[i] > a[i-1]){
v.push_back({a[i-1], 1});
v.push_back({a[i], -1});
}
if(a[i] <= a[i-1]){
v.push_back({a[i-1], -1});
v.push_back({a[i], 1});
}
}
sort(v.begin(), v.end());
long long sums = 0;
long long mx=0;
for(int i=0; i<n; i++){
int w = v[i].w;
sums+=w;
mx = max(sums,mx);
}
cout << mx;
}
/*
7
1 2 1 2 1 3 2
*/