2 条题解

  • 0
    @ 2023-10-26 21:01:37
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1000005;
    
    int n , k;
    bool a[ N ]; 
    
    signed main()
    {
    	cin >> n >> k;
    	for( int i = 1 ; i <= n ; i ++ )
    		cin >> a[ i ];
    	
    	int l = 1 , r = 0 , cnt = 0 , ans = INT_MIN;
    	while( l <= n )
    	{
    		while( r < n && cnt + ( ! a[ r + 1 ] ) <= k )
    			cnt += ( ! a[ ++ r ] );
    		
    		ans = max( ans , r - l + 1 );
    		cnt -= ( ! a[ l ++ ] );
    	}
    	
    	cout << ans;
    	return 0;
    }
    
    • 0
      @ 2023-10-26 21:01:27

      ··· #include <bits/stdc++.h> using namespace std; const int N = 1000005;

      int n , k; bool a[ N ];

      signed main() { cin >> n >> k; for( int i = 1 ; i <= n ; i ++ ) cin >> a[ i ];

      int l = 1 , r = 0 , cnt = 0 , ans = INT_MIN;
      while( l <= n )
      {
      	while( r < n && cnt + ( ! a[ r + 1 ] ) <= k )
      		cnt += ( ! a[ ++ r ] );
      	
      	ans = max( ans , r - l + 1 );
      	cnt -= ( ! a[ l ++ ] );
      }
      
      cout << ans;
      return 0;
      

      } ···

      • 1

      信息

      ID
      34
      时间
      1000ms
      内存
      256MiB
      难度
      10
      标签
      递交数
      2
      已通过
      2
      上传者