Cod sursa(job #1465680)

Utilizator GeiGeiGeorge Cioroiu GeiGei Data 27 iulie 2015 20:43:47
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <climits>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <map>
#include <algorithm>

using namespace std;

class test {
public:
    int x1;
    int x2;
    int x3;
};

int main() {
    freopen("loto.in", "r", stdin);
    //freopen("loto.out", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, s;
    cin >> n >> s;
    int* v = new int[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    map<int, test> ord;
    test a;
    for (int x1 = 1; x1 <= n; x1++) {
        for (int x2 = x1; x2 <= n; x2++) {
            for (int x3 = x2; x3 <= n; x3++) {
                int tot = v[x1] + v[x2] + v[x3];
                a.x1 = x1; a.x2 = x2; a.x3 = x3;
                ord[tot] = a;
            }
        }
    }
    for (map<int, test>::iterator it = ord.begin(); it != ord.end(); it++) {
        int k = it->first;
        if (k + k > s) {
            break;
        }
        int r = s - k;
        map<int, test>::iterator jt = ord.find(r);
        if (jt != ord.end()) {
            a = it->second;
            cout << v[a.x1] << " " << v[a.x2] << " " << v[a.x3] << " ";
            a = jt->second;
            cout << v[a.x1] << " " << v[a.x2] << " " << v[a.x3] << " ";
            return 0;
        }
    }
    cout << -1;

    return 0;
}