寒假训练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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章