Skip to content

Commit

Permalink
1806 parametric 2_pointer #2
Browse files Browse the repository at this point in the history
  • Loading branch information
goo-gy committed Feb 2, 2022
1 parent 99d2c9a commit 4b9f5d6
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions baekjoon/1806_parametric.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <vector>

#define INF 1234567890

using namespace std;

int N, S;
vector<int> v_num;

void solution()
{
cin >> N >> S;
v_num.resize(N);
for (int &num : v_num)
cin >> num;

int L = 0, R = -1;
long long sum = 0;
int minLen = INF;
while (R < N)
{
if (sum >= S)
{
minLen = min(minLen, R - L + 1);
sum -= v_num[L];
L++;
}
else
{
R++;
sum += v_num[R];
}
}
if (minLen == INF)
cout << "0\n";
else
cout << minLen << "\n";
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solution();
return 0;
}

0 comments on commit 4b9f5d6

Please sign in to comment.