Untitled
plain_text
a month ago
573 B
0
Indexable
Never
#include <bits/stdc++.h> int firstCircularTour(vector<int>& petrol, vector<int>& distance, int N) { int balance=0; int deficit=0; int start=0; for(int i=0;i<N;i++){ balance+=petrol[i]-distance[i]; if(balance<0){ start=i+1; //no need to check from start to i as if i fail from i i will fail from 0 as from 0 deficit+=balance; // i get some extra petrol before i reach i balance=0; } } // return balance+deficit; if(balance+deficit>=0) return start; else return -1; }