Cod sursa(job #1415386)
Utilizator | Andrei Roman andrei124 | Data | 4 aprilie 2015 15:01:25 |
---|---|---|---|
Problema | Loto | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.97 kb |
#include<fstream>
#include<algorithm>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
int v[101],w[1000001],z[7];
int main()
{
int n,i,cnt=1,s,a,b,c,k=1,j,x=1;
in>>n>>s;
for(i=1;i<=n;i++)in>>v[i];
i=1;
for(a=1;a<=n;a++)
for(b=1;b<=n;b++)
for(c=1;c<=n;c++)
{
w[k]=v[a]+v[b]+v[c];
j=s-w[k];
k++;
i=1;
while(i<=k&&w[i]!=j) i++;
if(i<=k&&cnt<=2)
{
z[x]=v[a];
x++;
z[x]=v[b];
x++;
z[x]=v[c];
x++;
cnt++;}
}
if(cnt==3)
{
sort(z+1,z+6);
for(i=1;i<x-1;i++)out<<z[i]<<" ";
out<<z[x-1];
}
if(cnt!=3)out<<-1;
return 0;
}