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