#include<bits/stdc++.h>
using namespace std;
int main()
{
//ios_base::sync_with_stdio(false);
int t;
cin>>t;
char c;
for(int i=0;i<t;i++)
{
int bulbs,rows,switches;
cin>>bulbs>>rows>>switches;
vector<int> state(rows,bulbs);//rows number of rows with value of each=bulbs
for(int j=0;j<rows;j++)
{
for(int k=0;k<bulbs;k++)
{
cin>>c;
if(c=='.')
state[j]--;
}
}
sort(state.begin(),state.end(),less<int>());
int ind=0;
while(switches>0&&ind<rows&&(bulbs-state[ind]>state[ind]))
{
//for(int j=0;j<rows;j++)
// cout<<state[j]<<" ";
//cout<<"\n";
state[ind]=bulbs-state[ind];
switches--;
ind++; //best answer received
//ind++;
//if(ind==rows)
// ind=0;
//total+=state[j];
}
if(switches!=0&&switches%2==1)
{
vector<int>::iterator it= min_element(state.begin(),state.end());
*it=bulbs-*it;
}
cout<<accumulate(state.begin(),state.end(),0)<<"\n";
}
}
Could tell me why am i getting wrong answer in SPOJ?
Seems to be working fine for custom test cases.