#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main() {
int N;
long long S;
cin >> N >> S;
vector<int> arr(N);
for (int i = 0; i < N; ++i) cin >> arr[i];
int minLength = INT_MAX;
int start = 0, end = 0;
long long sum = 0;
while (true) {
if (sum >= S) {
minLength = min(minLength, end - start);
sum -= arr[start++];
} else if (end == N) {
break;
} else {
sum += arr[end++];
}
}
cout << (minLength == INT_MAX ? 0 : minLength) << '\n';
return 0;
}
투포인터로 풀 수 있다.
시작점 끝점을 start, end로 두고 현재 부분합이 S 이상이면 길이 갱신, start 옮기기, 작으면 end 옮기기~ 를 반복...