fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n,k;
  6. cin>>n>>k;
  7.  
  8. vector<int> numbers(n);
  9.  
  10. for(auto& number: numbers){
  11. cin>>number;
  12. }
  13.  
  14. int smallest = INT_MAX, largest = INT_MIN;
  15. int countSmallest = 0, countLargest = 0;
  16.  
  17. for(int i=0; i<n; i++){
  18. int sum = 0;
  19.  
  20. for(int j=i; j<n; j++){
  21. sum += numbers[j];
  22.  
  23. if(sum == k){
  24. int length = j - i + 1;
  25.  
  26. if(length == largest)countLargest++;
  27. if(length == smallest)countSmallest++;
  28.  
  29. if(length > largest){
  30. largest = length;
  31. countLargest = 1;
  32. }
  33.  
  34. if(length < smallest){
  35. smallest = length;
  36. countSmallest = 1;
  37. }
  38.  
  39.  
  40. }
  41. }
  42. }
  43.  
  44. cout<<largest<<" "<<countLargest<<endl;
  45. cout<<smallest<<" "<<countSmallest;
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 5320KB
stdin
6 8
3 2 3 3 2 8
stdout
3 3
1 1