classSolution{public:staticboolcmp(constint& a,constint& b){returnabs(a)>abs(b);}intlargestSumAfterKNegations(vector<int>& nums,int k){sort(nums.begin(), nums.end(), cmp);for(int i =0; i < nums.size(); i++){if(nums[i]<0&& k >0){
nums[i]*=-1;
k--;}}if(k %2==1) nums[nums.size()-1]*=-1;int ans =0;for(int& n : nums) ans += n;return ans;}};
classSolution{public:intcanCompleteCircuit(vector<int>& gas, vector<int>& cost){int size = gas.size();int ans =0;int total =0, restTotal =0;for(int i =0; i < size; i++){int rest = gas[i]- cost[i];
total += rest;
restTotal += rest;if(total <0){
ans = i +1;
total =0;}}if(restTotal <0)return-1;return ans;}};
classSolution{public:intcandy(vector<int>& ratings){int n = ratings.size();
vector<int>assign(n,1);for(int i =1; i < n; i++){if(ratings[i]> ratings[i -1])
assign[i]= assign[i -1]+1;}for(int i = n -2; i >=0; i--){if(ratings[i]> ratings[i +1])
assign[i]=max(assign[i], assign[i +1]+1);}int ans =0;for(int& i : assign) ans += i;return ans;}};