intcandy(vector<int>& ratings){ int num = ratings.size(); int* ca = newint[num]; for (int i = 0; i < num; i++) ca[i] = 1; for (int i = 1; i < num; i++) if (ratings[i] > ratings[i - 1]) ca[i] = ca[i - 1] + 1; for (int i = num - 2; i >= 0; i--) if (ratings[i] > ratings[i + 1]) ca[i] = max(ca[i], ca[i + 1] + 1); int res = 0; for (int i = 0; i < num; i++) res += ca[i]; return res; }