Walk The Line
Problem LinkSolution by dudu — 100 pts
Code / Notes
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int N, S, L;
cin >> N >> S >> L;
S--;
vector<int> A(N-1);
for (auto &x : A) cin >> x;
vector<int> P(N);
for (int i = 1; i < N; i++)
P[i] = P[i-1] + A[i-1];
int ans = 0;
for (int l = 0; l < N; l++) {
for (int r = l; r < N; r++) {
if (!(l <= S and S <= r)) continue;
// eu consigo visitar todas as cidades de l até r?
int DL = P[S]-P[l];
int DR = P[r]-P[S];
int total = DL + DR + min(DL, DR);
if (total <= L) ans = max(ans, r-l+1);
}
}
cout << ans << endl;
}
Last updated 1 month ago