fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define io std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. #define file(name) {freopen(name".INP","r",stdin);freopen(name".OUT","w",stdout);}
  5. int main (){
  6. io;file("BEAUTY");
  7. int n,k;cin>>n>>k;
  8. vector<int> a(n);
  9. for(int i=0;i<n;i++){
  10. cin>>a[i];
  11. }
  12. int l=0,r=0, mac=0,sum=0;
  13. while(r<n){
  14. sum+=a[r];
  15. while(sum>k*(r-l+1)&&l<=r){sum-=a[l];l++ ; ;}
  16. if(sum==k*(r-l+1)&&r-l+1>mac){mac=r-l+1;}
  17. r++;
  18. }
  19. cout<<mac;
  20. return 0;}
  21.  
Success #stdin #stdout 4.1s 1279904KB
stdin
Standard input is empty
stdout
Standard output is empty