Pagini recente » Cod sursa (job #2971076) | Cod sursa (job #2384864) | Cod sursa (job #767910) | Cod sursa (job #1915456) | Cod sursa (job #1249860)
# include <bits/stdc++.h>
# define x first
# define y second
using namespace std;
ifstream fi("semne.in");
ofstream fo("semne.out");
const int nmax = 100005;
pair < int , int > s[nmax],v[nmax];
bool b[nmax];
int x,y;
int main(void)
{
int n,s1,Sum=0;
fi >> n >> s1;
srand(time(NULL));
for (int i=1,p,ok;i<=n;++i)
{
ok = rand() % 2;
fi>>p;
if (ok) s[++x].x=p,s[x].y=i,Sum+=p;
else Sum-=p,v[++y].x=p,v[y].y=i;
}
int p;
while (Sum != s1)
if (Sum < s1)
{
p = rand() % y;++p;
s[++x]=v[p];
Sum+=2 * v[p].x;
swap(v[p],v[y--]);
}
else
{
p = rand() % x;++p;
v[++y]=s[p];
Sum-=2 * s[p].x;
swap(s[p],s[x--]);
}
for (int i=1;i<=x;++i) b[s[i].y]=1;
for (int i=1;i<=n;++i) fo << (b[i] ? '+':'-');
return 0;
}