Pagini recente » Cod sursa (job #2073246) | Cod sursa (job #1585847) | Cod sursa (job #2912289) | Cod sursa (job #1490751) | Cod sursa (job #1962046)
#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[x] = pl.back();
pl.pop_back();
}else{
int x = rand();
x = x % ms.size();
s += 2 * a[ms[x]];
pl.push_back(ms[x]);
v[ms[x]] = 1;
ms[x] = ms.back();
ms.pop_back();
}
}
for(int i = 1; i <= n; ++i){
if(v[i] == 1)
g << '+';
else
g << '-';
}
return 0;
}