classSolution{public:intcanCompleteCircuit(vector<int>& gas, vector<int>& cost){int curSum =0;int min = INT_MAX;for(int i =0; i < gas.size(); i++){int rest = gas[i]- cost[i];
curSum += rest;if(curSum < min) min = curSum;}if(curSum <0)return-1;if(min >=0)return0;for(int i = gas.size()-1; i >=0; i--){int rest = gas[i]- cost[i];
min += rest;if(min >=0)return i;}return-1;}};
classSolution{public:intcandy(vector<int>& ratings){
vector<int>candyVec(ratings.size(),1);for(int i =1; i < ratings.size(); i++){if(ratings[i]> ratings[i -1]) candyVec[i]= candyVec[i -1]+1;}for(int i =ratings.size()-2; i >=0; i--){if(ratings[i]> ratings[i +1]) candyVec[i]=max(candyVec[i +1]+1, candyVec[i]);}int result =0;for(int i =0; i < candyVec.size(); i++) result += candyVec[i];return result;}};