Cod sursa(job #1284880)

Utilizator rangerChihai Mihai ranger Data 6 decembrie 2014 21:42:50
Problema Loto Scor 75
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 1.27 kb
#include<fstream>
#include<algorithm>
#include<vector>
using namespace std;

ifstream cin("loto.in");
ofstream cout("loto.out");

const  int nmax=101;

struct lol{
 int x,y,z,sum;};
lol a[nmax*nmax*nmax];

int n,s,i,j,k, b[nmax],l;

bool cmp(lol a, lol b)
{
    return a.sum < b.sum;
}
#define pb push_back
#define mp make_pair
#define mod 1234577
vector<pair<int,int> > h[mod];


int main()
{
    cin >> n >> s;

    for (i=1;i<=n;i++) cin >> b[i];

    for (i=1;i<=n;i++)
    for (j=1;j<=n;j++)
    for (k=1;k<=n;k++){
        l++;
        a[l].x=b[i]; a[l].y=b[j]; a[l].z=b[k];
        a[l].sum=b[i]+b[j]+b[k];
        int t=a[l].sum%mod;
        h[t].pb(mp(a[l].sum,l));
    }

    //sort(a+1,a+l+1,cmp);
    int gasit=0;
    for (i=1;i<=n && !gasit;i++)
    for (j=1;j<=n && !gasit;j++)
    for (k=1;k<=n && !gasit;k++){
        int s1 = s - b[i] - b[j] - b[k];
        if (s1<0) continue;
        int t=s1%mod;
        for (int g=0;g<h[t].size() && !gasit;g++)
            if (h[t][g].first==s1) {
                gasit=1;
                int l=h[t][g].second;
                cout<<b[i]<<" "<<b[j]<<" "<<b[k]<<" ";
                cout<<a[l].x<<" "<<a[l].y<<" "<<a[l].z;
            }
    }
    if (!gasit) cout << -1;
    return 0;
}