Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author : unlucky_13
- Problem_link :
- Category :
- Algorithm_Used :
- */
- #include<cstdio>
- #include<sstream>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<queue>
- #include<stack>
- #include<list>
- #include<iostream>
- #include<fstream>
- #include<numeric>
- #include<string>
- #include<vector>
- #include<cstring>
- #include<map>
- #include<iterator>
- #define i64 long long int
- //const long long int inf = 2147483647 ;
- //const int minx=;
- //const int maxn=;
- using namespace std;
- int compare(const void *a,const void *b){
- /*This will sort in increasing oder */
- int *x = (int *)a ;
- int *y = (int *)b ;
- return *x-*y ;
- }
- int main() {
- freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
- int c,s,I,ct=0;
- int cham[100000];
- double imb,avg ;
- while(scanf("%d %d",&c,&s)==2)
- {
- //if(ct) cout<<endl ;
- imb = 0 ;
- I = 0 ;
- avg = 0 ;
- for(int i=s;i<2*c;i++,I++) cham[I]=0 ;
- for(int i=0;i<s;i++,I++) {
- scanf("%d",&cham[I]) ;
- avg+=cham[I] ;
- }
- avg/=c ;
- qsort(cham,I,sizeof(int),compare) ;
- // for(int i=0;i<I;i++) cout<<cham[i]<<" " ;
- printf("Set #%d\n",++ct) ;
- for(int i=0;i<c;i++){
- printf(" %d:",i) ;
- if(cham[i]) cout<<" "<<cham[i];
- if(cham[I-i-1]) cout<<" "<<cham[I-i-1];
- imb +=abs(cham[i]+cham[I-i-1]-avg) ;
- cout<<endl ;
- }
- printf("IMBALANCE = %0.5lf\n\n",imb) ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment