Here's my code.Its working for the given test cases but giving a WA on submission.
include
include
include
include
include
include
include<string.h>
include
include
include
include
include
include
include
include
include
include
include
include<stdio.h>
using namespace std;
define INF (1<<29)
define SET(a) memset(a,-1,sizeof(a))
define ALL(a) a.begin(),a.end()
define CLR(a) memset(a,0,sizeof(a))
define FILL(a,v) memset(a,v,sizeof(a))
define PB push_back
define FOR(i,n) for(int i = 0;i<n;i++)
define PI acos(-1.0)
define EPS 1e-9
define MP(a,b) make_pair(a,b)
define min3(a,b,c) min(a,min(b,c))
define max3(a,b,c) max(a,max(b,c))
define READ freopen("input.txt", "r", stdin)
define WRITE freopen("output.txt", "w", stdout)
define LL long long
define MX 100010
define MOD 1000000007
double abss(double i) { return i>0 ?i:(-1.0*i); } int main(){ vector l; int n,s,element; int set = 1; while(cin>>n){ double sum = 0; cin>>s; FOR(i,s){ cin>>element; sum+=element; l.push_back(element); } double average = sum/n; if((l.size()%2)!=0){ l.push_back(0); } sort(l.begin(),l.end()); int iter = 0; cout<<"Set #"<<set<<endl; double balance = 0; FOR(i,n){ cout<<" "<<i<<": "; if(l[iter]!=0) cout<<l[iter]<<" "; if(l[l.size()-iter-1]!=0) cout<<l[l.size()-iter-1]<<endl; balance+=abss(((l[iter])+(l[l.size()-iter-1]))-(average)); iter++; } printf("IMBALANCE = %0.5f\n\n",balance); if(cin.eof()){ break; } set++; l.clear(); }
return 0;
}