Official
A - Buildings Editorial by en_translator
For beginners
- 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".
- 「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
Use a for
statement to check for each \(i=2,3,\ldots,N\) if \(H_i > H_1\).
If such an \(i\) was found, print that \(i\) and terminate the program at that point. Otherwise, print \(-1\).
Note that most programming languages adopt \(0\)-based indexing.
Sample code (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> h(n);
for(int i = 0; i < n; i++) cin >> h[i];
for(int i = 1; i < n; i++) {
if(h[i] > h[0]) {
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
}
Sample code (Python):
n = int(input())
h = list(map(int, input().split()))
for i in range(1, n):
if h[i] > h[0]:
print(i + 1)
exit()
print(-1)
posted:
last update: