## 11968 - In The Airport

Moderator: Board moderators

Decode
New poster
Posts: 1
Joined: Wed May 11, 2011 9:49 am

### 11968 - In The Airport

What is the problem in my code? Getting WA.

Code: Select all

``````#include<stdio.h>
#include<math.h>
#define Max 1001
#define Mx 1000000001
#define Min(a,b) ((a)<(b))?(a):(b)

unsigned long n,m,k;
double Sum,Av,C,D;
int p[Max],Q[Max],Cake[Max],Drink[Max];

int main()
{
int tc,i,j,Cnt=1;
scanf("%d",&tc);
while(tc--)
{
scanf("%lu%lu%lu",&n,&m,&k);
Sum=0;
for(i=1; i<=n; i++)
{
scanf("%lu",&p[i]);
Q[i]=p[i];
Sum+=Q[i];
}
Av=Sum/n;

for(i=1; i<=m; i++)
Cake[i]=Q[i];
for(i=m+1,j=1; i<=m+k; i++,j++)
Drink[j]=Q[i];

for(i=1; i<=m; i++)
{
if(fabs(Cake[i]-Av)>=fabs(Cake[i+1]-Av)) continue;
else break;
}
C=Cake[i];
for(i=1; i<=k; i++)
{
if(fabs(Drink[i]-Av)>=fabs(Drink[i+1]-Av)) continue;
else break;
}
D=Drink[i];
printf("Case #%d: %.0lf %.0lf\n",cnt++,C,D);
}
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11968 - In the Airport

It looks like your code assumes sorted input. My AC code does not.
Check input and AC output for thousands of problems on uDebug!

yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

### Re: 11968 - In the Airport

My program got WA, can anyone help me?

Code: Select all

``````#include <stdio.h>
#include <math.h>
int main()
{
int i,j,testcase,t,n,m,k,ans;
long long sum;
int cake[1000],drink[1000];
double average,dif,nowdif;
/*freopen("in11968.txt","r",stdin);*/
scanf("%d",&testcase);
for(t=1; t<=testcase; t++)
{
scanf("%d %d %d",&n,&m,&k);
sum=0;
for(i=0; i<m; i++)
{
scanf("%d",&cake[i]);
sum+=cake[i];
}
for(i=0; i<k; i++)
{
scanf("%d",&drink[i]);
sum+=drink[i];
}
for(i=m+k; i<n; i++)
{
scanf("%d",&j);
sum+=j;
}
average=(double)sum/n;

printf("Case #%d:",t);
dif=2147483647.0;
for(i=0; i<m; i++)
{
nowdif=fabs(cake[i]-average);
if(nowdif<dif)
{
dif=nowdif;
ans=cake[i];
}
else if(nowdif==dif)
{
if(cake[i]<ans) ans=cake[i];
}
}
printf(" %d",ans);
dif=2147483647.0;
for(i=0; i<k; i++)
{
nowdif=fabs(drink[i]-average);
if(nowdif<dif)
{
dif=nowdif;
ans=drink[i];
}
else if(nowdif==dif)
{
if(drink[i]<ans) ans=drink[i];
}
}
printf(" %d\n",ans);

}
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11968 - In the Airport

Try submitting this code again.
Check input and AC output for thousands of problems on uDebug!

graph_dp
New poster
Posts: 7
Joined: Fri Sep 14, 2012 8:33 am

### i am getting WA in uva=11968

Code: Select all

``````#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#define LL long long int

using namespace std;

struct data{

int val;
bool operator<(const data b)const{
return val>b.val;
}

};

int main () {

int kase,e,w;
cin>>kase;int y=1;
while(kase--){
data temp;
map<int,int>MP;
queue<int>q;
vector<int>v;
priority_queue<data>pq;
priority_queue<data>Q;
int n;
cin>>n>>e>>w;int a;
LL sum=0;
for(int i=0;i<n;i++){

cin>>a;temp.val=a;
q.push(a);
sum+=a;
pq.push(temp);
}
int avg=sum/n;
while(!pq.empty()){
//cout<<pq.top().val<<endl;

int value=abs(avg-pq.top().val);
if(avg>=pq.top().val){
MP[value]=pq.top().val;
v.push_back(value);
}
pq.pop();
}
sort(v.begin(),v.end());
int m=MP[v[0]];
int h=MP[v[1]];

int cnt=1;
cout<<"Case #"<<y<<": ";
while(!q.empty()){
if(m==q.front()){
cout<<m;
}
if(h==q.front()){

cout<<h;
}
q.pop();
if(cnt<2){cout<<" ";}
cnt++;

}
cout<<endl;
y++;

}
return 0;
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: i am getting WA in uva=11968

Try input:

Code: Select all

``````1
5 2 2
1 2 1 2 2``````
Check input and AC output for thousands of problems on uDebug!

t.tahasin
New poster
Posts: 38
Joined: Tue May 28, 2013 11:21 pm

### Re: 11968 - In the Airport

Getting WA.
In another thread I got a input
1
5 2 2
1 2 1 2 2
for this input my program outputs
Case #1: 2 2
Is it correct?

Code: Select all

``````deleted after acc.
``````
Last edited by t.tahasin on Wed Jul 03, 2013 11:23 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11968 - In the Airport

Input:

Code: Select all

``````1
4 2 2
2 3 2 3
``````
AC output:

Code: Select all

``Case #1: 2 2``
Check input and AC output for thousands of problems on uDebug!

t.tahasin
New poster
Posts: 38
Joined: Tue May 28, 2013 11:21 pm

### Re: 11968 - In the Airport

Thanks brianfry713. I got acc.

tomb_raider
New poster
Posts: 2
Joined: Tue Oct 28, 2014 8:42 am

### Re: 11968 - In The Airport

Code: Select all

``````#include <stdio.h>
#include <stdlib.h>
int cmpfunc(const void *a,const void *b)
{
return(*(long long int*)a-*(long long int*)b);
}
int main()
{
long long int arr_total[10000],arr_cake[10000],arr_drinks[10000];
long long int Z=1,A1,A2,x,A,test,total,cake,drinks;
double avg,arr_1[10000],arr_2[10000],min1,min2;
scanf("%lld",&test);
while(test--)
{
avg=0,x=0,A1=0,A2=0,arr_cake[0]=0,arr_drinks[0]=0;
scanf("%lld %lld %lld",&total,&cake,&drinks);
for(A=0;A<cake;A++)
{
scanf("%lld",&arr_cake[A]);
arr_total[x]=arr_cake[A];
x++;
}
for(A=0;A<drinks;A++)
{
scanf("%lld",&arr_drinks[A]);
arr_total[x]=arr_drinks[A];
x++;
}

for(A=x;A<total;A++)
{
scanf("%lld",&arr_total[A]);
}
for(A=0;A<total;A++)
{
avg=avg+(double)arr_total[A];
}
avg=avg/total;
x=0;
qsort(arr_cake,cake,sizeof(long long int),cmpfunc);
qsort(arr_drinks,drinks,sizeof(long long int),cmpfunc);
for(A=0;A<cake;A++)
{
if(avg>(double)arr_cake[A])
arr_1[A]=avg-(double)arr_cake[A];
else
arr_1[A]=(double)arr_cake[A]-avg;
}
for(A=0;A<drinks;A++)
{
if(avg>(double)arr_drinks[A])
arr_2[A]=avg-(double)arr_drinks[A];
else
arr_2[A]=(double)arr_drinks[A]-avg;
}
for(A=0;A<cake;A++)
{
min1=arr_1[0];
A1=A;
if(min1>arr_1[A+1])
{
min1=arr_1[A+1];
}
else
{
break;
}
}
for(A=0;A<drinks;A++)
{
min2=arr_2[0];
A2=A;
if(min2>arr_2[A+1])
{

min2=arr_2[A+1];
}
else
{
break;
}
}
printf("Case #%lld: %lld %lld\n",Z,arr_cake[A1],arr_drinks[A2]);
Z++;
}
return 0;
}``````
Last edited by brianfry713 on Tue Jan 06, 2015 5:43 am, edited 1 time in total.