Advertisement
DaniDori

Untitled

Nov 4th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4. int main()
  5. {
  6. int n, x, sum=0, j, min=1001;
  7. cin >> n >> x;
  8. int* arr = new int[n];
  9. for (int i = 0; i < n; i++)
  10. cin >> arr[i];
  11. for (int i = 0; i < n; i++)
  12. {
  13. sum = 0;
  14. j = i;
  15. while (sum <= x)
  16. {
  17.  
  18. sum += arr[j];
  19. if ((j - i + 1 < min) && sum >= x)
  20. min = j - i + 1;
  21. if (j == n)
  22. break;
  23. j++;
  24.  
  25. }
  26. }
  27. if (min == 1001)
  28. {
  29. cout << -1;
  30. return 0;
  31. }
  32. cout << min;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement