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 P2,P3,,PNP_2,P_3,\dots,P_N. Let this value be MM. Then, person 11 is the strongest if and only if P1P_1 is greater than MM. Thus, the answer is the larger of M+1P1M + 1 - P_1 and 00. Note that just printing M+1P1M + 1 - P_1 is insufficient, because it prints a negative value when person 11 is already the strongest in the input.

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

Sample code (C++):

Copy
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n;
  5. cin >> n;
  6. vector<int> p(n);
  7. for (int i = 0; i < n; i++) {
  8. cin >> p[i];
  9. }
  10. int m = 0;
  11. for (int i = 1; i < n; i++) {
  12. m = max(m, p[i]);
  13. }
  14. cout << max(0, m + 1 - p[0]) << endl;
  15. }
#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):

Copy
  1. n = int(input())
  2. p = list(map(int, input().split()))
  3. m = 0
  4. for i in range(1, n):
  5. m = max(m, p[i])
  6. print(max(0, m + 1 - p[0]))
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:



2025-03-14 (Fri)
02:15:46 +00:00