1 条题解

  • 2
    #include<iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n;
        cin>>n;
        vector<long long>a(n);
        for(int i=0; i<n; ++i) {
            cin>>a[i];
        }
        long long base=1;
        long long c=0;
        vector<long long>valid_m;
        for(int i=1; i<n; ++i) {
            long long ai=a[i];
            long long ai_prev=a[i-1];
            int s;
            if(ai>ai_prev) {
                s=1;
            } else if(ai==ai_prev) {
                s=0;
            } else {
                s=-1;
            }
            c+=s;
            if(c==0) {
                if(ai==a[0]) {
                    ++base;
                }
            } else {
                long long delta=ai-a[0];
                if(delta%c!=0) {
                    continue;
                }
                long long m_candidate=delta/c;
                if(m_candidate>0) {
                    valid_m.push_back(m_candidate);
                }
            }
        }
        long long best_m=1;
        int max_count=0;
        if(!valid_m.empty()) {
            sort(valid_m.begin(),valid_m.end());
            int current_count=1;
            long long current_m=valid_m[0];
            max_count=1;
            best_m=current_m;
            for(size_t i=1; i<valid_m.size(); ++i) {
                if(valid_m[i]==current_m) {
                    ++current_count;
                } else {
                    current_m=valid_m[i];
                    current_count=1;
                }
                if(current_count>max_count) {
                    max_count=current_count;
                    best_m=current_m;
                } else if(current_count==max_count&&current_m<best_m) {
                    best_m=current_m;
                }
            }
        }
        cout<<base+max_count<<'\n';
        cout<<best_m<<'\n';
        return 0;
    }
    
  • 1

信息

ID
3080
难度
9
分类
(无)
标签
递交数
4
已通过
1
通过率
25%
上传者