Pagini recente » Cod sursa (job #2743043) | Cod sursa (job #163606) | Cod sursa (job #1567334) | Cod sursa (job #1874479) | Cod sursa (job #1962040)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream f("semne.in");
ofstream g("semne.out");
const int NMax = 50003;
int n;
ll S,s;
int a[NMax];
bool v[NMax];
vector<int> pl,ms;
int main()
{
f >> n >> S;
for(int i = 1; i <= n; ++i){
f >> a[i];
if(s < S){
pl.push_back(i);
v[i] = 1;
s += a[i];
}else{
ms.push_back(i);
s -= a[i];
}
}
srand(time(NULL));
while(s != S){
if(s > S && pl.size() != 0){
int x = rand();
x = x % pl.size();
s -= 2 * a[pl[x]];
ms.push_back(pl[x]);
v[pl[x]] = 0;
pl.erase(pl.begin() + x);
}else{
int x = rand();
x = x % ms.size();
s += 2 * a[ms[x]];
pl.push_back(ms[x]);
v[ms[x]] = 1;
ms.erase(ms.begin() + x);
}
}
for(int i = 1; i <= n; ++i){
if(v[i] == 1)
g << '+';
else
g << '-';
}
return 0;
}