Elections
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 nn n candidates, numbered from 1 to nn n . Candidate nn n is the opposition candidate. There are mm m polling stations in the constituency, numbered from 1 to mm 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 nn n and mm m (2≤n≤1002≤n≤100 2\le n\le 100 ; 1≤m≤1001≤m≤100 1\le m \le 100 ) — the number of candidates and the number of polling stations. The next mm m lines contain the election results at each polling station with nn n numbers on each line. In the ii i -th line the jj j -th number is a**i,jai,j a_{i,j} — the number of votes cast for the candidate jj j at the station ii i (0≤a**i,j≤10000≤ai,j≤1000 0\le a_{i,j} \le 1,000 ).
Output
In the first line output integer kk k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output kk k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at kk k stations, output any one of them.
Examples
Input
Copy
5 3
6 3 4 2 8
3 7 5 6 7
5 2 4 7 9
Output
Copy
2
3 1
Input
Copy
2 1
1 1
Output
Copy
0
Input
Copy
3 3
2 3 8
4 2 9
3 1 7
Output
Copy
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.
正确
#include<bits/stdc++.h>
using namespace std;
const int N=105;
const int INF=0x3f3f3f;
int a[N][N];
int stu[N];
vector<int>w[N];
struct node
{
int val,pos;
}p[N];
bool cmp(node a,node b)
{
return a.val<b.val;
}
int main()
{
int n,m;
cin>>n>>m;
int maxn=-INF;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
stu[j]+=a[i][j];
maxn=max(maxn,stu[j]);
}
if(maxn>stu[n])
{
cout<<0<<endl;
return 0;
}
int minn=INF;
int minpos=-1;
bool flag=0;
for(int i=1;i<n;i++)
{
int x=stu[i]-stu[n];
if(x>=0) {flag=1;break;}
for(int j=1;j<=m;j++){
p[j].val=a[j][i]-a[j][n];
p[j].pos=j;
}
sort(p+1,p+1+m,cmp);
for(int s=1;s<=m;s++)
{
x-=p[s].val;
w[i].push_back(p[s].pos);
if(x>=0) break;
}
int tr=w[i].size();
//minn=min(minn,tr);
if(minn>tr)
{
minn=tr;
minpos=i;
}
}
if(flag) {
cout<<0<<endl;
return 0;
}
cout<<minn<<endl;
for(int i=0;i<w[minpos].size();i++)
cout<<w[minpos][i]<<' ';
cout<<endl;
return 0;
}
思路
枚举每个人,只要删除一些投票站后,票数多于第n个人,就可
在其中找删除数量最小的。