Cod sursa(job #3304221)

Utilizator Cezar2009Cezar Mihai Titihazan Cezar2009 Data 21 iulie 2025 20:51:56
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 4.07 kb
//https://www.nerdarena.ro/problema/loto1
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("fast-math")
//#pragma GCC optimize ("unroll-loops")
//#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
//#include <cstring>
//#include <cmath>
//#include <bitset>
//#include <queue>
//#include <stack>
//#include <utility>
//#include <algorithm>
//#include <string>
//#include <map>
#include <unordered_map>
//#include <set>
//#include <unordered_set>
//#include <cstdint>
//#include <climits>
//#include <iomanip>
//#include <cstdio>
using namespace std;

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

template<typename T>
class FastIO
{
private:
    ifstream& fin;
    ofstream& fout;

    static constexpr int IN_BUF_SIZE = 262144;
    static constexpr int OUT_BUF_SIZE = 262144;

    char inBuf[IN_BUF_SIZE];
    int inPos = IN_BUF_SIZE, inBytes = IN_BUF_SIZE;

    char outBuf[OUT_BUF_SIZE];
    int outPos = 0;

    inline char getChar()
    {
        if (inPos == inBytes)
        {
            fin.read(inBuf, IN_BUF_SIZE);
            inBytes = fin.gcount();
            inPos = 0;
            if (inBytes == 0)
                return -1;
        }

        return inBuf[inPos++];
    }


public:
    FastIO(ifstream& finStream, ofstream& foutStream) : fin(finStream), fout(foutStream) {}

    inline void writeChar(char c)
    {
        if (outPos == OUT_BUF_SIZE)
        {
            fout.write(outBuf, outPos);
            outPos = 0;
        }
        outBuf[outPos++] = c;
    }
    T readInt()
    {
        char c;
        bool neg = false;

        do
        {
            c = getChar();
            if (c == -1)
                return -1;
        } while ((c < '0' || c > '9') && c != '-');

        if (c == '-')
        {
            neg = true;
            c = getChar();
        }

        T res = 0;
        while (c >= '0' && c <= '9')
        {
            res = res * 10 + (c - '0');
            c = getChar();
        }
        return neg ? -res : res;
    }

    void writeInt(T x)
    {
        if (x < 0)
        {
            writeChar('-');
            x = -x;
        }

        char temp[20];
        int len = 0;
        do
        {
            temp[len++] = '0' + x % 10;
            x /= 10;
        } while (x);

        while (len--)
            writeChar(temp[len]);
    }

    void flush()
    {
        if (outPos > 0)
        {
            fout.write(outBuf, outPos);
            outPos = 0;
        }
    }

};

int v[110], s, sum;
int n;
unordered_map <int, tuple<int, int, int>> mp;
void generare()
{
	int i, j, k;
	int sum;
	for (i = 1; i <= n; ++i)
	{
		for (j = 1; j <= n; ++j)
		{
			for (k = 1; k <= n; ++k)
			{
				sum = v[i] + v[j] + v[k];
				mp[sum] = { i,j,k };
			}
		}
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int i, j, k;
    FastIO <int> io(fin, fout);

    n = io.readInt();
    s = io.readInt();

	for (i = 1; i <= n; ++i)
	{
        v[i] = io.readInt();
	}

	generare();

	for (auto it=mp.begin();it!=mp.end();++it)
	{
		int a1 = get<0>(it->second);
		int b1 = get<1>(it->second);
		int c1 = get<2>(it->second);

		//cout << it->first << " " << a1 << " " << b1 << " " << c1 << " ";
		int key = s - it->first;
		//cout << key << "\n";
		if (mp.find(key) != mp.end()) 
		{
			int a2 = get<0>(mp[key]);
			int b2 = get<1>(mp[key]);
			int c2 = get<2>(mp[key]);

            io.writeInt(v[a1]);
            io.writeChar(' ');
            io.writeInt(v[b1]);
            io.writeChar(' ');
            io.writeInt(v[c1]);
            io.writeChar(' ');
            io.writeInt(v[a2]);
            io.writeChar(' ');
            io.writeInt(v[b2]);
            io.writeChar(' ');
            io.writeInt(v[c2]);
            io.flush();
			//fout << v[a1] << " " << v[b1] << " " << v[c1] << " " << v[a2] << " " << v[b2] << " " << v[c2] << "\n";
			return 0;
		}
	}

    io.writeInt(-1);
    io.flush();
    //fout << "-1";
	return 0;
}