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 . Let this value be . Then, person is the strongest if and only if is greater than . Thus, the answer is the larger of and . Note that just printing is insufficient, because it prints a negative value when person 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;
}
#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]))
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: