Skip to content

Commit

Permalink
Merge pull request #15 from ehotinger/ehotinger-candies
Browse files Browse the repository at this point in the history
Update Candies Solution
  • Loading branch information
ehotinger authored Mar 15, 2018
2 parents f068191 + d661159 commit 11a7628
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Candies/Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@
#include <vector>
using namespace std;

int GetRequiredCandies(vector<int> Students) {
int N = Students.size();
int TotalCandies = 0;
long long GetRequiredCandies(vector<long long> Students) {
long long N = Students.size();
long long TotalCandies = 0;

vector<int> Left = vector<int>(N, 1);
vector<int> Right = vector<int>(N, 1);
vector<long long> Left = vector<long long>(N, 1);
vector<long long> Right = vector<long long>(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]);
}

return TotalCandies;
}

int main() {
int N, Score;
long long N, Score;
cin >> N;

vector<int> Students;
vector<long long> Students;

for (int i = 0; i < N; i++) {
for (long long i = 0; i < N; i++) {
cin >> Score;
Students.push_back(Score);
}

cout << GetRequiredCandies(Students) << endl;

return 0;
}
}

0 comments on commit 11a7628

Please sign in to comment.