寒假訓練20200116

B Codeforces 1267E

Problem Description

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.
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.
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.

Input

The first line of the input contains two integers n and m (2≤n≤100; 1≤m≤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 ai,j — the number of votes cast for the candidate j at the station i (0≤ai,j≤1000).

Output

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.

Examples

Input
5 3
6 3 4 2 8
3 7 5 6 7
5 2 4 7 9
Output
2
3 1

Input
2 1
1 1
Output
0

Input
3 3
2 3 8
4 2 9
3 1 7
Output
3
1 2 3

Note

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.


題意

給定m個投票站和n個人,每個投票站對於每個人有一個票數,所有投票站的票數和爲這個人的最終票數,票數高的人獲勝。現在可以取消幾個投票站,使得第n個人不能獲勝(除第n個人外,任意一人的得票大於或等於第n個人,第n個人則無法獲勝)。問最少需要取消幾個投票站?

思路

思想:思維。
對於每一個人別與第n個人考慮,最少需要取消幾個投票站才能是這個人的得票大於等於第n個人。再將這n-1個人的取最小值即可。
然後對於每一個人,我們可以將每一個投票站的兩人得票之差算出,排序,依次判斷即可。

坑點

一開始把所有投票站的所有人放在一起考慮了,貪心策略有誤。


Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<VII> VIII;
typedef pair<int, int> PII;

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)

const int N = 100 + 5;
const ll MOD = 1e9 + 7;

int n, m;

struct S
{
    int sub;
    int state;
} sub[N];

int max_pos = 1;

int a[N][N];
int vote[N];
VI ANS[N];

bool cmp(S aa, S bb)
{
    return aa.sub < bb.sub;
}

int main()
{
    scanf("%d%d", &n ,&m);
    rep(i,1,m) rep(j,1,n) scanf("%d", &a[i][j]);
    rep(i,1,n) rep(j,1,m) vote[i] += a[j][i];
    int minn = 1;
    rep(i,1,n-1)
    {
        rep(j,1,m) sub[j].sub = a[j][i] - a[j][n], sub[j].state = j;
        sort(sub+1, sub+1+m, cmp);
        int val = vote[i] - vote[n];
        if(val >= 0)
            break;
        rep(j,1,m)
        {
            val -= sub[j].sub;
            ANS[i].push_back(sub[j].state);
            if(val >= 0)
                break;
        }
        if(ANS[i].size() < ANS[minn].size())
            minn = i;
    }
    int sz = ANS[minn].size();
    printf("%d\n", sz);
    rep(i,0,sz-1)
    {
        printf("%d ", ANS[minn][i]);
    }
    printf("\n");
    return 0;
}
發佈了44 篇原創文章 · 獲贊 6 · 訪問量 4551
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章