Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- int n, x, sum=0, j, min=1001;
- cin >> n >> x;
- int* arr = new int[n];
- for (int i = 0; i < n; i++)
- cin >> arr[i];
- for (int i = 0; i < n; i++)
- {
- sum = 0;
- j = i;
- while (sum <= x)
- {
- sum += arr[j];
- if ((j - i + 1 < min) && sum >= x)
- min = j - i + 1;
- if (j == n)
- break;
- j++;
- }
- }
- if (min == 1001)
- {
- cout << -1;
- return 0;
- }
- cout << min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement