codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

570A.md (2471B)


      1 Source: https://codeforces.com/problemset/problem/570/A
      2 
      3 A. Elections
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
     22 
     23 The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
     24 
     25 At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
     26 
     27 Determine who will win the elections.
     28 
     29 Input
     30 
     31 The first line of the input contains two integers *n*, *m* (1 ≤ *n*, *m* ≤ 100) — the number of candidates and of cities, respectively.
     32 
     33 Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1 ≤ *j* ≤ *n*, 1 ≤ *i* ≤ *m*, 0 ≤ *a**ij* ≤ 109) denotes the number of votes for candidate *j* in city *i*.
     34 
     35 It is guaranteed that the total number of people in all the cities does not exceed 109.
     36 
     37 Output
     38 
     39 Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 3 3  
     47 1 2 3  
     48 2 3 1  
     49 1 2 1
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 2
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 3 4  
     62 10 10 3  
     63 5 1 6  
     64 2 2 2  
     65 1 5 7
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 1
     72 ```
     73 
     74 Note
     75 
     76 Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
     77 
     78 Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.