Submission
Status:
[PPxSS][PPxSS]
Score: 0
User: Punnawith
Problemset: จุดแวะพัก
Language: cpp
Time: 0.033 second
Submitted On: 2025-03-23 10:26:27
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define Student pair<int, string>
vector<Student> studentList;
int totalStudents, targetScore;
int main() {
cin >> totalStudents >> targetScore;
for (int i = 0; i < totalStudents; i++) {
string inputLine;
getline(cin, inputLine);
string name;
string number;
int index = 0;
for (char ch : inputLine) {
if (isalpha(ch)) {
name.push_back(ch);
} else if (ch == ' ') {
number.clear();
} else {
number.push_back(ch);
if (stoi(number) == targetScore) {
studentList.push_back({index, name});
break;
}
index++;
}
}
}
if (studentList.empty()) {
cout << -1;
return 0;
}
sort(studentList.begin(), studentList.end());
for(int i = 0; i < 3; i++) {
cout << studentList[i].second << ' ';
}
return 0;
}