Codeforces Round #386 (Div. 2), problem: (E) Numbers Exchange Solution in C/C++

By |2017-04-07T22:11:46+00:00January 6th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

Codeforces Round #386 (Div. 2), problem: (E) Numbers Exchange Solution in C/C++     #include<stdio.h> #include<stdlib.h> typedef unsigned u; u N[222222],X[222222],C[222222],H[222222]; int F(const void*x,const void*y) { if(N[*(u*)x]>N[*(u*)y])return 1; if(N[*(u*)x]<N[*(u*)y])return-1; return 0; } int main() { u n,m,i,o,e,h,os=1,es=2,g=0; scanf("%u%u",&n,&m);h=n>>1; if(n&1){printf("-1\n");return 0;} for(i=-1;++i<n;X[i]=i)scanf("%u",N+i); qsort(X,n,sizeof(u),F); for(i=o=e=0;++i<n;)if(N[X[i]]==N[X[i-1]])C[X[i]]=1; for(i=n;i--;)if(!C[X[i]]) [...]