Cod sursa(job #1522771)

Utilizator FairPlay94George Cioroiu FairPlay94 Data 11 noiembrie 2015 22:56:12
Problema Loto Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <cstdio>
#include <iostream>
#include <set>
#include <climits>
#include <map>
#include <algorithm>
#include <list>
#include <vector>
#include <utility>

using namespace std;

class tripla {
public:
    int x, y, z;
    tripla(int vX, int vY, int vZ) : x(vX), y(vY), z(vZ) {}
    tripla() {}
};

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

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

    int n, s;
    cin >> n >> s;
    int v[105];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    map<int, tripla> m;
    for (int i = 0; i < n; i++) {
        for (int j = i ; j < n; j++) {
            for (int k = j; k < n; k++) {
                tripla a(v[i], v[j], v[k]);
                int t = v[i] + v[j] + v[k];
                m[t] = a;
            }
        }
    }
    for (map<int, tripla>::iterator it = m.begin(); it != m.end(); it++) {
        int aux = it->first;
        if (aux + aux > s) {
            break;
        }
        map<int, tripla>::iterator jt = m.find(s - aux);
        if (jt != m.end()) {
            cout << it->second.x << " " << it->second.y << " " << it->second.z << " " << jt->second.x << " " << jt->second.y << " " << jt->second.z;
            return 0;
        }
    }

    return 0;
}