Cod sursa(job #1417423)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 10 aprilie 2015 12:20:54
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>

using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

const int SMAX = 999983;
const int NMax = 105;
struct node{
    int sum,x,y,z;
};
vector < node > a[SMAX];
int v[NMax];

int main()
{
    int n,s;
    fin >> n >> s;
    for(int i = 1; i <= n; i++){
        fin >> v[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                int gh = v[i] + v[j] + v[k];
                if(gh < s){
                    int ad = v[i] + v[j] + v[k];
                    if(a[ad].empty()){
                        node ans;
                        ans.sum = ad;
                        ans.x = v[i];
                        ans.y = v[j];
                        ans.z = v[k];
                        a[ad].push_back(ans);
                    }
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                int val = s - v[i] - v[j] - v[k];
                if(val > 0 && !a[val].empty()){
                    fout << a[val][0].x << " " << a[val][0].y << " " << a[val][0].z << " " << v[i] << " " << v[j] << " " << v[k];
                    return 0;
                }
            }
        }
    }
    fout << -1;
    return 0;
}