| 8 | int arr[100001]; |
| 9 | |
| 10 | int main(void){ |
| 11 | ios::sync_with_stdio(false); |
| 12 | cin.tie(0); |
| 13 | |
| 14 | cin>>N>>S; |
| 15 | for(int i=0; i<N; i++){ |
| 16 | cin>>arr[i]; |
| 17 | } |
| 18 | |
| 19 | int left = 0; |
| 20 | int right = 0; |
| 21 | int ans = 987654321; |
| 22 | int sum = arr[0]; |
| 23 | while(left<=right && right<N){ |
| 24 | |
| 25 | if(sum < S) |
| 26 | sum += arr[++right]; |
| 27 | else if(sum == S){ |
| 28 | ans = min(ans, right-left+1); |
| 29 | sum += arr[++right]; |
| 30 | } |
| 31 | else if(sum > S){ |
| 32 | ans = min(ans, right-left+1); |
| 33 | sum -= arr[left++]; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if(ans == 987654321) |
| 38 | cout<<"0\n"; |
| 39 | else |
| 40 | cout<<ans<<"\n"; |
| 41 | return 0; |
| 42 | } |
nothing calls this directly
no outgoing calls
no test coverage detected