Cod sursa(job #2168288)

Utilizator laurastanStan Laura laurastan Data 14 martie 2018 10:17:59
Problema Loto Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");



struct str
{int x;
int y;
int z;

}v[110];
int ct;
int var;
bool cmp(str va,str vb)
{if(va.x+va.y+va.z<vb.x+vb.y+vb.z) return 1;
else return 0;

}
int main()
{int i,n,s,j,l,st,dr,m;
long long a[110];
f>>n;
f>>s;
for(i=1;i<=n;i++)
    f>>a[i];
for(i=1;i<=n;i++)
for(j=i;j<=n;j++)
for(l=j;l<=n;l++)
{ct++;
    v[ct].x=a[i];
    v[ct].y=a[j];
    v[ct].z=a[l];

}

cout<<"\n\n\n";
sort(v+1,v+ct+1,cmp);



for(i=1;i<=ct;i++)
{st=1;dr=ct;
    while(st<=dr)
{m=(st+dr)/2;
if(v[i].x+v[i].y+v[i].z+v[m].x+v[m].y+v[m].z==s) {g<<v[i].x<<" "<<v[i].y<<" "<<v[i].z<<" "<<v[m].x<<" "<<v[m].y<<" "<<v[m].z<<"\n";var=1;break;}
if(v[i].x+v[i].y+v[i].z+v[m].x+v[m].y+v[m].z<s) {st=m+1;}
if(v[i].x+v[i].y+v[i].z+v[m].x+v[m].y+v[m].z>s) {dr=m-1;}

}
if(var==1)break;


}




    return 0;
}