Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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)

AltStyle によって変換されたページ (->オリジナル) /