Pagini recente » Cod sursa (job #1337907) | Cod sursa (job #2545605) | Cod sursa (job #3279420) | Profil osztianpalmarozalia | Cod sursa (job #971402)
Cod sursa(job #971402)
#include <cstdio>
#include <ctime>
#include <algorithm>
using namespace std;
#define NMAX 50001
#define LL long long
LL i, N, S;
LL LM, LP, sum;
LL v[NMAX];
LL P[NMAX], M[NMAX];
LL x;
bool Conf[NMAX];
int main() {
freopen("semne.in","r",stdin);
freopen("semne.out","w",stdout);
scanf("%lld%lld", &N, &S);
srand(time(NULL));
for (i = 0; i < N; ++i) {
scanf("%lld", &v[i]);
x = rand() % 2;
Conf[i] = x;
if (!x) {
sum += (1LL * v[i]);
P[LP++] = i;
}
else {
sum -= (1LL * v[i]);
M[LM++] = i;
}
}
while (sum != S) {
if (sum > S) {
x = rand() % LP;
sum -= (2 * v[P[x]]);
M[LM++] = P[x];
Conf[P[x]] = 1 - Conf[P[x]];
swap(P[x], P[--LP]);
}
else {
x = rand() % LM;
sum += (2 * v[M[x]]);
P[LP++]= M[x];
Conf[M[x]] = 1 - Conf[M[x]];
swap(M[x], M[--LM]);
}
}
for (i = 0; i < N; ++i) {
if (!Conf[i])
printf("+");
else
printf("-");
}
return 0;
}