Submission

Status:

[PPPPPP-SSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: onlyme910

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

Language: cpp

Time: 0.005 second

Submitted On: 2026-03-11 11:14:13

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

#define l long

l int n;
int max_count = 0;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n;
    int arr[n];
    set<double> num;
    for(int i = 0;i<n;i++){
        cin >> arr[i];
        num.insert(arr[i]);
    }
    for(int i = 0;i<n-1;i++){
        double c = double(arr[i]+arr[i+1])/2;
        num.insert(c);
    }
    bool xaxis;
    bool first = false;
    for(double x : num){
        int count  =0;
        if(x == arr[0]){
            count++;
            first = true;
        }
        else if(x < arr[0]){
            xaxis = true;
        }
        else if(x > arr[0]){
            xaxis = false;
        }
        for(int i = 1;i<n;i++){
            if(!first){
                if(xaxis && x > arr[i]){
                    count++;
                    xaxis = false;
                }
                else if(!xaxis && x < arr[i]){
                    count++;
                    xaxis = true;
                }
                else if(x == arr[i]){
                    count++;
                    if(x < arr[i+1]){
                        xaxis = true;
                    }
                    else if(x > arr[i+1]){
                        xaxis = false;
                    }
                }
            }
            else {
                first = false;
                if(x < arr[1]){
                    xaxis = true;
                }
                else if(x > arr[1]){
                    xaxis = false;
                }
                continue;
            }
        }
        max_count = max(max_count,count);
    }

    cout << max_count;
}