School Trip Destination Ranking
InterviewTime limit1sMemory limit128 MB
Count how many of n students want each of m destinations, then print destination numbers by descending count with ties broken by ascending number.
- Level
Easy3 of 10
- Topics
- Array, Sorting, Implementation
- Solved
- No attempts yet
Problem
A school is planning a field trip, so it surveyed its students. The students are numbered from to , and the candidate destinations are numbered from to . Each student submitted a form marking for a place they want to visit and for a place they do not want to visit.
Write a program that prints the destination numbers in descending order of how many students want to visit each place. When two places are wanted by the same number of students, print them in ascending order of destination number.
Input
The first line contains the number of students and the number of candidate destinations , separated by a space.
Each of the next lines describes one student's answers: the -th of these lines gives student 's values separated by spaces, where means the student wants to visit that place and means they do not.
, .
Output
Print the destination numbers on a single line separated by single spaces, ordered by the number of students who want to visit (most first), breaking ties by ascending destination number. End the line with a newline.