James and the menus
Practice
3.3 (18 votes)
Arrays
Implementation
1 D
C++
Data structures
Problem
85% Success 8363 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

James visits a restaurant, looks at the menu, and realizes that there is no price on it. Since he wanted to know the prices before he orders, he looked up the restaurant online and found $$n$$ different versions of the menu. He knew from experience that usually the menu which has the maximum number of items that have the maximum price on that item between the menus is the most updated one and if there are multiple menus with that condition the one with the maximum average price is the most updated one. Help him find the most updated menu.

In other words, a price on an item is good if it is the maximum price on that item among all menus, and a menu is the most updated one if it has the maximum number of good prices on it.
If there are multiple menus with the maximum number of good prices, the menu with the higher price average is the most updated one.

Input format

  • The first line contains integers $$n$$ and $$m$$ that denote the number of menus and the number of items on each menu respectively.
  • The next $$n$$ line each contains $$m$$ integers represented as $$A_{ij}$$, the $$j_{th}$$ price on the $$i_{th}$$ menu.

Output format

Print a single number denoting the number of the most updated menu.

It is guaranteed that the answer is unique.

Constraints

$$1 \le n, m \le 10^{3}$$

$$ 1 \le A_{ij} \le 10^{9}$$

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
83 votes
Tags:
SortingArraysImplementationData StructuresSet1-D
Points:20
31 votes
Tags:
ArraysData Structures1-DMath
Points:20
30 votes
Tags:
ArraysData StructuresEasyOne-dimensional