From d661159b8fb92055d47ea0d1f93580c9933abd6e Mon Sep 17 00:00:00 2001 From: Eric Hotinger Date: Thu, 15 Mar 2018 11:06:27 -0700 Subject: [PATCH] Update Candies Solution They changed the test cases to be outside of the `int` range. Fixes #7 --- Candies/Solution.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Candies/Solution.cpp b/Candies/Solution.cpp index 1adf62b..068bb9c 100644 --- a/Candies/Solution.cpp +++ b/Candies/Solution.cpp @@ -2,24 +2,24 @@ #include using namespace std; -int GetRequiredCandies(vector Students) { - int N = Students.size(); - int TotalCandies = 0; +long long GetRequiredCandies(vector Students) { + long long N = Students.size(); + long long TotalCandies = 0; - vector Left = vector(N, 1); - vector Right = vector(N, 1); + vector Left = vector(N, 1); + vector Right = vector(N, 1); - for (int i = N - 2; i >= 0; i--) { + for (long long i = N - 2; i >= 0; i--) { if (Students[i + 1] < Students[i]) Right[i] = 1 + Right[i + 1]; } - for (int i = 1; i < N; i++) { + for (long long i = 1; i < N; i++) { if (Students[i - 1] < Students[i]) Left[i] = 1 + Left[i - 1]; } - for (int i = 0; i < N; i++) { + for (long long i = 0; i < N; i++) { TotalCandies += max(Right[i], Left[i]); } @@ -27,12 +27,12 @@ int GetRequiredCandies(vector Students) { } int main() { - int N, Score; + long long N, Score; cin >> N; - vector Students; + vector Students; - for (int i = 0; i < N; i++) { + for (long long i = 0; i < N; i++) { cin >> Score; Students.push_back(Score); } @@ -40,4 +40,4 @@ int main() { cout << GetRequiredCandies(Students) << endl; return 0; -} \ No newline at end of file +}