A. Still Typing
Hint 1 (English)Store the 10 names in a fixed array in the exact same order given in the problem statement.
Hint 2 (English)Find the index $$$i$$$ ($$$0 \le i \lt 10$$$) that has the maximum typing speed, then print the name at index $$$i$$$.
Editorial (English)We are given the names of $$$10$$$ participants in a fixed order, followed by $$$10$$$ integers representing their typing speeds.
- Store the names in an array of strings
names of size $$$10$$$ matching the order in the statement. - Read the $$$10$$$ speeds into an array
arr (or process them on the fly). - Track the maximum speed
mx found so far and its corresponding index idx. - Finally, output
names[idx].
- Time Complexity: $$$\mathcal{O}(1)$$$ (since the number of participants is fixed at $$$10$$$).
- Space Complexity: $$$\mathcal{O}(1)$$$.
تلميح 1 (عربي)خزّن أسماء الـ 10 متسابقين في Array ثابتة بنفس الترتيب المذكور في نص المسألة بالظبط.
تلميح 2 (عربي)دوّر على الـ Index صاحب أكبر سرعة كتابة، وبعدين اطبع الاسم الموجود في نفس الـ Index.
الشرح (عربي)المسألة بتدينا أسماء $$$10$$$ متسابقين بترتيب ثابت، وبعدها بتدينا $$$10$$$ أرقام بيمثلوا سرعة كل واحد فيهم بالترتيب.
- هنعمل Array من نوع
string نحط فيها الأسماء بنفس الترتيب المكتوب في المسألة. - هنستقبل الـ $$$10$$$ أرقام ونعدي عليهم بـ Loop عشان نجيب أكبر رقم (
mx) ونحتفظ بمكانه (idx). - في الآخر هنطبع الاسم اللي في المكان ده
names[idx].
- التعقيد الزمني (Time Complexity): $$$\mathcal{O}(1)$$$ لأن عدد العناصر ثابت وهو $$$10$$$.
- مساحة الذاكرة (Space Complexity): $$$\mathcal{O}(1)$$$.
Solution Code (C++) ```cpp
include <bits/stdc++.h>
using namespace std;
define int long long
define endl "\n"
signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr);
// Store participant names in the exact given order
string names[] = {"Andrew", "Moaz", "Hani", "Dabour", "Seif",
"Omar", "Hadeer", "Mariam", "Mai", "Basant"};
int arr[10];
for (int i = 0; i < 10; i++) {
cin >> arr[i];
}
int mx = 0;
int idx = -1;
// Find the index of the maximum typing speed
for (int i = 0; i < 10; i++) {
if (arr[i] > mx) {
mx = arr[i];
idx = i;
}
}
cout << names[idx] << endl;
return 0;}