I was solving this problem on codeforces here, the code displays right ans but it exceeds the memory limit in the site. Can't figure out why. Also tried to use vectors but doesn't work. Pls help me fix it.
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,c,deny=0;
int groups[n];
scanf("%d %d %d",&n,&a,&b);
for(int i=0;i<n;i++){
cin>>groups[i];
}
int two_one=b*2;
//two kinds of tables:one seater,2 seater
//find no of ppl denied service
for(int j=0;j<n;j++){
if(groups[j]==1 and a!=0){
a-=1;
}
else if(groups[j]==1 and a==0){
two_one-=1;
b-=1;
}
else if(groups[j]==1 and a==0 and two_one==0){
deny+=1;
}
else if(groups[j]==2 and b!=0){
b-=1;
}
else if(groups[j]==2 and b==0){
deny+=2;
}
}
printf("%d",deny);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire