Uva 410 : Station Balance.Wrong answer
Difference between en1 and en2, changed 1,838 character(s)
Here's my code.Its working for the given test cases but giving a WA on submission.↵

#include<iostream>↵
#include<list>↵
#include<string>↵
#include<cstring>↵
#include<sstream>↵
#include<cctype>↵
#include<string.h>↵
#include<algorithm>↵
#include<cmath>↵
#include<stack>↵
#include<fstream>↵
#include<cstdlib>↵
#include<vector>↵
#include<map>↵
#include<set>↵
#include<utility>↵
#include<iomanip>↵
#include<queue>↵
#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<int> 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;↵
}
Solution link : http://ideone.com/JcEHbc↵
Problem link  : [Uva 410](https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB4QFjAAahUKEwiJiIG--5PGAhVHNLwKHeKwAI0&url=https%3A%2F%2Fuva.onlinejudge.org%2Findex.php%3Foption%3Dcom_onlinejudge%26Itemid%3D8%26page%3Dshow_problem%26problem%3D351&ei=-fR_VcmnD8fo8AXi4YLoCA&usg=AFQjCNGmB5PiczhzJ1v2cq81qjI9Ns_geA&sig2=E_AWcKwk907BP_W86vgSKw&bvm=bv.96041959,d.dGc)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English suggi_d_luffy 2015-06-16 13:06:35 1838
en1 English suggi_d_luffy 2015-06-16 13:00:01 1829 Initial revision (published)