We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66c785c commit e36c5ffCopy full SHA for e36c5ff
2022/Contests/Div 2/778/Explanations/Maximum Cake Tastiness Explanation.txt
@@ -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