codeforces-scrape

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

1267E.md (2885B)


      1 Source: https://codeforces.com/problemset/problem/1267/E
      2 
      3 E. Elections
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected.
     22 
     23 There are $n$ candidates, numbered from 1 to $n$. Candidate $n$ is the opposition candidate. There are $m$ polling stations in the constituency, numbered from 1 to $m$. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate.
     24 
     25 Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected.
     26 
     27 Input
     28 
     29 The first line of the input contains two integers $n$ and $m$ ($2\le n\le 100$; $1\le m \le 100$) — the number of candidates and the number of polling stations. The next $m$ lines contain the election results at each polling station with $n$ numbers on each line. In the $i$-th line the $j$-th number is $a_{i,j}$ — the number of votes cast for the candidate $j$ at the station $i$ ($0\le a_{i,j} \le 1\,000$).
     30 
     31 Output
     32 
     33 In the first line output integer $k$ — the minimal number of the polling stations in which you need to cancel the election results. In the second line output $k$ integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at $k$ stations, output any one of them.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 5 3
     41 6 3 4 2 8
     42 3 7 5 6 7
     43 5 2 4 7 9
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 2
     50 3 1
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 2 1
     57 1 1
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 0
     64 ```
     65 
     66 Input
     67 
     68 ```
     69 3 3
     70 2 3 8
     71 4 2 9
     72 3 1 7
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 3
     79 1 2 3
     80 ```
     81 
     82 Note
     83 
     84 In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.