#include "race.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ar array
const int MOD = 1e9 + 7,INF = 1e9, N = 2e5 + 5;
int best_path(int n, int k, int H[][2], int L[]){
vector <vector <pair<int,int>>> g(n + 1);
vector <int> a;
for(int i = 0;i < n - 1;i++){
g[H[i][0]].pb({H[i][1] , L[i]});
g[H[i][1]].pb({H[i][0] , L[i]});
a.pb(L[i]);
}
int l = 0, r = 0;
int sum = a[l];
int ans = INF;
while(l < n - 1&& r < n - 1){
if(sum == k){
ans = min(ans , (r - l + 1));
}
else if(sum > k){
sum -= a[l];
l++;
}
else if(sum < k && r < n - 2){
r++;
sum += a[r];
}
else{
break;
}
}
if(ans == INF){
return -1;
}
else{
return ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |