#include<stdio.h>
#include<math.h>
int main(){
long int a,b,c,ar[100010]={0},cr[100010]={0},i,l,n,min=10000000,u=0,z;
scanf("%ld",&n);
c=n;
while(n--){
scanf("%ld %ld",&a,&b);
if(a==b){
ar[a]++;
// cr[a]++;
}else{
ar[a]++;
// cr[a]++;
cr[b]++;
}
}
l=(c+1)/2;
for(i=0;i<=100005;i++){
if(cr[i]+ar[i]>=l){
u=1;
if(l<=ar[i]){
min=0;
break;
}else{
if(cr[i]>=l-ar[i]){
if(min>l-ar[i]){
min=l-ar[i];
}
}
}
}
}
if(u==1){
printf("%ld\n",min);
}else{
printf("Impossible\n");
}
return 0;
}
#include<math.h>
int main(){
long int a,b,c,ar[100010]={0},cr[100010]={0},i,l,n,min=10000000,u=0,z;
scanf("%ld",&n);
c=n;
while(n--){
scanf("%ld %ld",&a,&b);
if(a==b){
ar[a]++;
// cr[a]++;
}else{
ar[a]++;
// cr[a]++;
cr[b]++;
}
}
l=(c+1)/2;
for(i=0;i<=100005;i++){
if(cr[i]+ar[i]>=l){
u=1;
if(l<=ar[i]){
min=0;
break;
}else{
if(cr[i]>=l-ar[i]){
if(min>l-ar[i]){
min=l-ar[i];
}
}
}
}
}
if(u==1){
printf("%ld\n",min);
}else{
printf("Impossible\n");
}
return 0;
}
No comments:
Post a Comment