class Solution {
public:
    int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
        int sum=0;
        int start=0;
        int minsum=INT_MAX;
    //从0开始求sum,最低点小于0是不行的,所以我们直接找最低点处开始
        for(int i=0;i<gas.size();i++)
        {
            sum+=gas[i]-cost[i];
            if(sum<minsum)
            {
                start=i+1;
                minsum=sum;
            }
        }
        if(sum<0)
        {
            return -1;
        }
        return start==gas.size()?0:start;
    }
};