Please sign in first.
Official
B - Takahashi's Failure Editorial by en_translator
The problem can be rephrased as follows: “among Foods \(B_1, B_2, \ldots, B_K\), is there a food having the best tastiness of the \(N\) foods (allowing ties)?”
This can be determined as follows, for example.
- Find the maximum tastiness of the \(N\) foods. (Let this value be \(M\).)
- For \(j=1,2,\ldots , K\), check if \(A_{B_j}=M\).
- If there are one or more such \(j\), the answer is
Yes; otherwise, the answer isNo.
This can be written with for statements and if statements.
Beware of the range of indices.
Also, be careful not to output Yes multiple times or output No after Yes.
Sample code in C++:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, k, m;
int a[100], b[100];
cin >> n >> k;
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < k; i++)cin >> b[i];
m = -1;
for (int i = 0; i < n; i++)m = max(m, a[i]);
for (int i = 0; i < k; i++) {
if (a[b[i] - 1] == m) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
Sample code in Python:
n,k= map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
m=max(a)
flag=False
for i in range(k):
if a[b[i]-1]==m:
flag=True
if flag:
print("Yes")
else:
print("No")
posted:
last update: