Cod sursa(job #1048373)

Utilizator MancasAlinaMancas Alina MancasAlina Data 5 decembrie 2013 19:36:25
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.53 kb
#include <fstream>
#include <algorithm>
using namespace std;
 
int n, st, dr,i,j,k,s1,x,mid;
int v[105], s;
bool ok;
 
struct date{
                int a;
                int b;
                int c;
                int d;
            } sum[1000005];
 
bool cmp(const date &a1, const date &b1)
{
    return(a1.a<b1.a);
}
int main()
{
    ifstream f("loto.in");
    ofstream g("loto.out");
    f>>n;
    f>>s;
    for(i=1;i<=n;i++)
        f>>v[i];
    for(i=1;i<=n;i++)
        for(j=i;j<=n;j++)
            for(k=j;k<=n;k++)
            {
                x++;
                sum[x].a=v[i]+v[j]+v[k];
                sum[x].b=v[i];
                sum[x].c=v[j];
                sum[x].d=v[k];
            }
    sort(sum+1,sum+x+1,cmp);
    ok=1;
    for(i=1;i<=n && ok;i++)
        for(j=i;j<=n && ok;j++)
            for(k=j;k<=n && ok;k++)
            {
                s1=s-v[i]-v[j]-v[k];
                st=1;dr=x;
                while(st<=dr && ok)
                {
                    mid=(st+dr)/2;
                    if(sum[mid].a>s1)
                        dr=mid-1;
                    else
                    if(sum[mid].a<s1)
                        st=mid+1;
                    else
                        ok=0;
                }
                if(!ok)
                {
                    g<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<sum[mid].b<<" "<<sum[mid].c<<" "<<sum[mid].d<<"\n";
                }
            }
    if(ok)
        g<<"-1";
    f.close();g.close();
    return 0;
}