Official

A - To Be Saikyo Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).


First, find the maximum value of \(P_2,P_3,\dots,P_N\). Let this value be \(M\). Then, person \(1\) is the strongest if and only if \(P_1\) is greater than \(M\). Thus, the answer is the larger of \(M + 1 - P_1\) and \(0\). Note that just printing \(M + 1 - P_1\) is insufficient, because it prints a negative value when person \(1\) is already the strongest in the input.

For the details on implementation, please refer to the following sample codes.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int m = 0;
    for (int i = 1; i < n; i++) {
        m = max(m, p[i]);
    }
    cout << max(0, m + 1 - p[0]) << endl;
}

Sample code (Python):

n = int(input())
p = list(map(int, input().split()))
m = 0
for i in range(1, n):
    m = max(m, p[i])
print(max(0, m + 1 - p[0]))

posted:
last update: