Official
B - Next Editorial by en_translator
First, find the maximum value of \(A_1, A_2, \ldots, A_N\).
Once you find the maximum value, which we denote by \(M\), all that left is to find the maximum value among \(A_1, A_2, \ldots, A_N\) that are not equal to \(M\).
Sample code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int m = *max_element(a.begin(), a.end());
int ans = 0;
for (int e : a) if (e != m) ans = max(ans, e);
cout << ans << endl;
}
posted:
last update: