THPTTD_112 - Dãy có giá trị trung bình lớn nhất

Xem dạng PDF

Gửi bài giải

Điểm: 10,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: average.inp
Output: average.out

Tác giả:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Go, Java, JavaScript, Kotlin, Pascal, Perl, PHP, Python, Ruby, Rust, Scratch, Swift

Trong trường hợp đề bài hiển thị không chính xác, bạn có thể tải đề bài tại đây: Đề bài


Bình luận

Hãy đọc nội quy trước khi bình luận.



  • 5
    lephuochauhungvuong  đã bình luận lúc 11, Tháng 3, 2025, 7:54
    #include<bits/stdc++.h>
    using namespace std;
    
    #define int long long
    #define fi first
    #define se second
    #define pb push_back
    #define el '\n'
    
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef string str;
    typedef unsigned uns;
    
    const long long MOD = 1e9 + 7;
    const long long inf = 1e18 + 7;
    
    void input(){
        if( fopen( "inp.txt", "r") ){
            freopen( "inp.txt", "r", stdin );
            freopen( "out.txt", "w", stdout );
        }
    }
    
    void submit(){
        #define name "average"
        freopen( name".inp", "r", stdin );
        freopen( name".out", "w", stdout );
    }
    
    // justiin
    
    int n, ma = -inf;
    int ans = 1, a[100005];
    
    signed main(){
        ios_base::sync_with_stdio(0);
        cin.tie(0);
    
        //input();
        submit();
    
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i], ma = max(ma, a[i]);
        a[n + 1] = inf;
    
        for(int i = 1; i <= n; i++){
            if(a[i] == ma){
                int j = i;
                while(a[i + 1] == ma) i++;
                ans = max(ans, i - j + 1);
            }
        }
    
        cout << ans;
    
        return 0;
    }
    

  • 0
    Uoao1807  đã bình luận lúc 14, Tháng 12, 2024, 17:54

    bi timeout hoai vay :/


    • 0
      KS_TDN_LDMQ  đã bình luận lúc 5, Tháng 3, 2025, 10:50

      using string