fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. vector<int>arr={1,1,1,1,2};
  8. int k=3;
  9. int maxlen=0;
  10. for(int i=0;i<arr.size();i++){
  11. int sum=0;
  12. for(int j=i;j<arr.size();j++){
  13. sum+=arr[j];
  14. if(sum==k){
  15. maxlen=max(maxlen,j-i+1);
  16. }
  17.  
  18. }
  19. }
  20. cout<<maxlen;
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
3