Cod sursa(job #18644)

Utilizator radoo_sk8erTrandafir Radu radoo_sk8er Data 18 februarie 2007 12:53:31
Problema Tricouri Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 2, Clasa a 9-a si gimnaziu Marime 0.82 kb
# include <fstream.h>
int v[6][21];
void main()
{
ifstream fi;
ofstream fo;
fi.open("tricouri.in");
fo.open("tricouri.out");
int m,k,p,ok=0;
long int x,i,j,n,s=0,c;
fi>>n;fi>>m;
for(i=1;i<=n;i++){fi>>x;
		  for(j=2;j<=20;j++){
				     if(x%j==0){if(x>=v[1][j]){v[5][j]=v[4][j];v[4][j]=v[3][j];v[2][j]=v[1][j];v[1][j]=x;}
						else if(x>=v[2][j]){v[5][j]=v[4][j];v[4][j]=v[3][j];v[2][j]=x;}
						     else if(x>=v[3][j]){v[5][j]=v[4][j];v[4][j]=v[3][j];v[3][j]=x;}
							  else if(x>=v[4][j]){v[5][j]=v[4][j];v[4][j]=x;}
							       else if(x>v[5][j])v[5][j]=x;
					       }
				    }
		 }
for(i=1;i<=m;i++){fi>>k;fi>>p;
		  for(j=1;j<=k;j++){s=s+v[j][p];if(v[j][p]==0) ok=1;}
		  if(s==0)fo<<-1<<'\n';
		  else if(ok==1)fo<<s+3*p<<'\n';
		       else fo<<s<<'\n';
		 s=0;ok=0;
		 }
fi.close();
fo.close();
}