Cod sursa(job #2038632)

Utilizator LucaSeriSeritan Luca LucaSeri Data 13 octombrie 2017 21:11:25
Problema Loto Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <map>
using namespace std;

int v[101];
const int MOD = 100000;
ifstream f("loto.in");
ofstream g("loto.out");
struct nr{int a, b, c;};
map<int, nr> sume[MOD+1];
int main(){
    int n, s;
    f >> n >> s;
    for(int i = 0; i < n; ++i){
        f >> v[i];
    }
    for(int i = 0; i < n; ++ i){
        for(int j = 0; j < n; ++ j){
            for(int k = 0; k < n; ++k){
                int sum = v[i] + v[j] + v[k];
                nr aux;
                aux.a = v[i]; aux.b = v[j]; aux.c = v[k];
                sume[sum%MOD][sum] = aux;
                if(sume[(s-sum)%MOD].find(s-sum) != sume[(s-sum)%MOD].end()){
                    nr temp = sume[(s-sum)%MOD][s-sum];
                    g << v[i] << ' ' << v[j] << ' ' << v[k] << ' ' << temp.a << ' ' << temp.b << ' ' << temp.c;
                    return 0;
                }
            }
        }
    }

    g << -1;
    return 0;
}