Submission

Status:
[PPPPPPPPPPPPPPP]

Score: 100

User: Nathlol2

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

Language: cpp

Time: 0.024 second

Submitted On: 2025-03-25 21:18:09

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define tiii tuple<int, int, int>
#define ar array
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>
#define ff first
#define ss second
#define rep(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e;i>=s;i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
template <class T>
void print_v(vector<T> &v) { for (auto x : v) cout << x << " "; cout << "\n"; }
#define MX INT_MAX
#define MN INT_MIN
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define read(type) readInt<type>()
ll min(ll a,int b) { if (a<b) return a; return b; }
ll min(int a,ll b) { if (a<b) return a; return b; }
ll max(ll a,int b) { if (a>b) return a; return b; }
ll max(int a,ll b) { if (a>b) return a; return b; }
ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }
bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }
void YY() { cout<<"YES\n"; }
void NN() { cout<<"NO\n"; }
void Yes() { cout<<"Yes\n"; }
void No() { cout<<"No\n"; }
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
void solve(){
    int n;
    cin >> n;
    vi a(n + 1);
    cf(i, 1, n){
        cin >> a[i];
    }
    vector<pii> p;
    int prev = a[1];
    cf(i, 2, n){
        p.pb({max(prev, a[i]), -1});
        p.pb({min(prev, a[i]), 1});
        prev = a[i];
    }
    int s = 0;
    int ans = 0;
    sort(all(p));
    for(auto [v, w] : p){
        s += w;
        ans = max(ans, s);
    }
    cout << ans << '\n';
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc = 1;
    //cin >> tc;
    while(tc--){
        solve();
    }
}