Cod sursa(job #866363)

Utilizator ericptsStavarache Petru Eric ericpts Data 27 ianuarie 2013 22:08:32
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <algorithm>
#include <fstream>
#include <tr1/unordered_map>
using namespace std;
int v[101],n,S;
ifstream in("loto.in");
ofstream out("loto.out");
struct triplu
{
    int x,y,z;
};
tr1::unordered_map<int,triplu> hsh;
int main()
{
    int i,j,k;
    triplu x;
    in >> n >> S;
    for(i=1;i<=n;++i)
        in >> v[i];
    for(i=1;i<=n;++i)
        for(j=1;j<=n;++j)
            for(k=1;k<=n;++k)
                hsh[v[i]+v[j]+v[k]] = (triplu){i,j,k};
    for(i=1;i<=n;++i)
        for(j=1;j<=n;++j)
            for(k=1;k<=n;++k)
    {
        if(S - v[i]-v[j]-v[k] > 0)
            if(hsh.count(S-v[i]-v[j]-v[k]))
        {
            out << i << " " << j << " " << k << " ";
            x = hsh[S-v[i]-v[j]-v[k]];
            out << x.x << " " << x.y << " " << x.z << "\n";
            return 0;
        }
    }
    out << "-1\n";
}