Skip to content

Commit e36c5ff

Browse files
Create Maximum Cake Tastiness Explanation.txt
1 parent 66c785c commit e36c5ff

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
We can always perform an operation to make any two elements adjacent. It is always better to make the greatest 2 elements neighbours
2+
3+
The answer is the sum of the 2 largest elements.
4+
5+
------
6+
7+
void solve()
8+
{
9+
int no_of_elements;
10+
cin >> no_of_elements;
11+
12+
vector <int> A(no_of_elements + 1);
13+
for(int i = 1; i <= no_of_elements; i++)
14+
{
15+
cin >> A[i];
16+
}
17+
18+
sort(A.begin() + 1, A.end());
19+
reverse(A.begin() + 1, A.end());
20+
21+
long long sum = A[1] + A[2];
22+
cout << sum << "\n";
23+
}

0 commit comments

Comments
 (0)